How to: Create a Custom Appointment Recurrence Form (Method 1)

This document describes how to create a custom form and replace the standard appointment recurrence editing form with a newly created form. Method 1 uses the AppointmentRecurrenceForm descendant. Use this technique to modify the default form layout or the form’s behavior.

Show MeA complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T220994.

The following example illustrates how you can customize the default recurrence dialog by changing captions and initializing editors.

Create an AppointmentRecurrenceForm descendant. Use the default constructor code to perform required initialization for the editors located on the form.

Default recurrence form is invoked from the AppointmentForm by clicking the Recurrence button.

To invoke a custom recurrence dialog instead of a default one, create an AppointmentForm descendant. Override the CreateAppointmentRecurrenceForm method with the code that creates a custom recurrence form. It is necessary because the AppointmentRecurrenceForm constructor requires an AppointmentFormController instance, which is accessible within the AppointmentForm class scope.

Handle the SchedulerControl.EditAppointmentFormShowing event, to substitute a default appointment form with a custom one.

The example calls the SchedulerControl.CreateAppointment method with parameters required to invoke the recurrence appointment dialog.

C#:Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CustomRecurrenceFormDescendantSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.schedulerControl1.EditAppointmentFormShowing += schedulerControl1_EditAppointmentFormShowing;
            this.Shown += Form1_Shown;
        }

        void schedulerControl1_EditAppointmentFormShowing(object sender, DevExpress.XtraScheduler.AppointmentFormEventArgs e)
        {
            // Recurrence form allows editing only daily recurring appointments. 
            MyAppointmentEditForm myForm = new MyAppointmentEditForm(schedulerControl1,
                e.Appointment, e.OpenRecurrenceForm, DevExpress.XtraScheduler.RecurrenceType.Daily);
            myForm.ShowDialog();
            e.Handled = true;

        }

        void Form1_Shown(object sender, EventArgs e)
        {
            this.schedulerControl1.CreateAppointment(false, true);
        }
    }
}

C#:MyAppointmentEditForm.cs

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CustomRecurrenceFormDescendantSample
{
    public class MyAppointmentEditForm : AppointmentForm
    {
        RecurrenceType recurringType;

        public MyAppointmentEditForm(SchedulerControl control, Appointment apt,
            bool openRecurrenceForm, RecurrenceType type)
            : base(control, apt, openRecurrenceForm)
        {
            recurringType = type;
        }

        protected override Form CreateAppointmentRecurrenceForm(Appointment patternCopy,
            FirstDayOfWeek firstDayOfWeek)
        {
            return new MyAppointmentRecurrenceForm(patternCopy, firstDayOfWeek,
                this.Controller, this.recurringType);
        }
    }

}

C#:MyAppointmentRecurrenceForm.cs

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CustomRecurrenceFormDescendantSample
{
    public class MyAppointmentRecurrenceForm : AppointmentRecurrenceForm
    {
        public MyAppointmentRecurrenceForm(Appointment pattern,
            FirstDayOfWeek firstDayOfWeek, AppointmentFormControllerBase controller,
            RecurrenceType type) : base(pattern, firstDayOfWeek, controller)
        {
            base.dailyRecurrenceControl1.Enabled = false;
            base.weeklyRecurrenceControl1.Enabled = false;
            base.monthlyRecurrenceControl1.Enabled = false;
            base.yearlyRecurrenceControl1.Enabled = false;
            switch (type) {
                case RecurrenceType.Daily:
                    base.dailyRecurrenceControl1.Enabled = true;
                    break;
                // Code for other RecurrenceType cases if required.
            }

            base.grpRecurrencePattern.Text =
                "You can edit only daily recurring appointments";
            base.Text = "Appointment Recurrence: Modified Form";
        }
    }

}

 

赞(3)
未经允许不得转载:TaKaSa » How to: Create a Custom Appointment Recurrence Form (Method 1)