Back to Devexpress

RecurrenceControlBase Class

windowsforms-devexpress-dot-xtrascheduler-dot-ui-719f1645.md

latest15.1 KB
Original Source

RecurrenceControlBase Class

A base class for recurrence controls available in the XtraScheduler library.

Namespace : DevExpress.XtraScheduler.UI

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
[ComVisible(false)]
public class RecurrenceControlBase :
    XtraUserControl,
    IBatchUpdateable,
    IBatchUpdateHandler
vb
<ComVisible(False)>
Public Class RecurrenceControlBase
    Inherits XtraUserControl
    Implements IBatchUpdateable,
               IBatchUpdateHandler

Remarks

This class implements the common functionality used by recurrence date-time controls. You should use this base class to create custom descendant recurrence controls.

The following properties and methods are specific for the RecurrenceControlBase :

Example

This example shows how you can implement a custom recurrence control and use it in your appointment editing form. A control that allows you to specify hourly recurrence is created by inheriting from the RecurrenceControlBase class. A custom form used to set the Appointment.RecurrenceInfo property is displayed instead of the default appointment editing form. To accomplish this, the SchedulerControl.EditAppointmentFormShowing event is handled.

csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
using System;

namespace E558
{
    public partial class XtraForm1 : AppointmentRecurrenceForm
    {
        public XtraForm1(Appointment pattern, FirstDayOfWeek fdow, AppointmentFormController afc)
            : base(pattern, fdow, afc)
        {
            //InitializeComponent();
            checkEdit1.Tag = RecurrenceType.Hourly;
            UnsubscribeRecurrenceTypeControlsEvents();
            SubscribeRecurrenceTypeControlsEvents();
            SetRecurrenceType(this.GetRecurrenceType());
        }

        protected override void InitializeControls(FirstDayOfWeek firstDayOfWeek) {
            InitializeComponent();
            base.InitializeControls(firstDayOfWeek);
        }

        protected override void SubscribeRecurrenceTypeControlsEvents()
        {
            base.SubscribeRecurrenceTypeControlsEvents();
            if(checkEdit1 != null)
                checkEdit1.EditValueChanged += new EventHandler(this.chkRecurrenceTypeChanged);
        }
        protected override void UnsubscribeRecurrenceTypeControlsEvents()
        {
            base.UnsubscribeRecurrenceTypeControlsEvents();
            if (checkEdit1 != null)
                checkEdit1.EditValueChanged -= new EventHandler(this.chkRecurrenceTypeChanged);
        }
        protected override void ChangeCurrentRecurrenceControl()
        {
            if (this.CurrentRecurrenceControl != null)
            {
                this.CurrentRecurrenceControl.Visible = false;
            }
            switch (this.GetRecurrenceType())
            {
                case RecurrenceType.Daily:
                    this.CurrentRecurrenceControl = this.dailyRecurrenceControl1;
                    break;

                case RecurrenceType.Weekly:
                    this.CurrentRecurrenceControl = this.weeklyRecurrenceControl1;
                    break;

                case RecurrenceType.Monthly:
                    this.CurrentRecurrenceControl = this.monthlyRecurrenceControl1;
                    break;
                case RecurrenceType.Hourly:
                    this.CurrentRecurrenceControl = this.hourRecurrenceControl1;
                    break;

                default:
                    this.CurrentRecurrenceControl = this.yearlyRecurrenceControl1;
                    break;
            }

            this.CurrentRecurrenceControl.Visible = true;

        }
        protected override void SetRecurrenceType(RecurrenceType type)
        {
            if (type == RecurrenceType.Hourly && checkEdit1 != null)
            {
                    checkEdit1.Checked = true;
                    return;
            }
                base.SetRecurrenceType(type);
        }
    }
}
csharp
using DevExpress.XtraScheduler.UI;
using System;

namespace E558
{
    public partial class HourRecurrenceControl : RecurrenceControlBase
    {
        public HourRecurrenceControl():base()
        {
            InitializeComponent();
            this.UpdateControlsCore();
            this.SubscribeControlsEvents();

        }
        protected override void SubscribeControlsEvents()
        {
            base.SubscribeControlsEvents();
            this.spinEdit1.EditValueChanged += new EventHandler(spinEdit1_EditValueChanged);
        }
        protected override void UnsubscribeControlsEvents()
        {
            base.UnsubscribeControlsEvents();
            this.spinEdit1.EditValueChanged -= new EventHandler(spinEdit1_EditValueChanged);
        }

        void spinEdit1_EditValueChanged(object sender, EventArgs e)
        {
            base.RecurrenceInfo.Periodicity = base.Validator.GetIntegerValue(this.spinEdit1.EditValue);
        }
        protected override void UpdateControlsCore()
        {
            base.UpdateControlsCore();
            this.spinEdit1.EditValue = base.RecurrenceInfo.Periodicity;
        }
    }
}
csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
using System.Windows.Forms;

namespace E558
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            schedulerControl1.EditAppointmentFormShowing+=schedulerControl1_EditAppointmentFormShowing;
        }

        private void schedulerControl1_EditAppointmentFormShowing(object sender, AppointmentFormEventArgs e)
        {
            using(var frm = new MyAppointmentForm(sender as SchedulerControl, e.Appointment, e.OpenRecurrenceForm))
                e.DialogResult = frm.ShowDialog();
            e.Handled = true;
        }
    }
    public class MyAppointmentForm : AppointmentForm
    {
        public MyAppointmentForm(SchedulerControl control, Appointment apt)
            : base(control, apt)
        {
        }
        public MyAppointmentForm(SchedulerControl control, Appointment apt,bool openRecurrenceForm)
            : base(control, apt, openRecurrenceForm)
        {
        }
        protected override Form CreateAppointmentRecurrenceForm(Appointment patternCopy, FirstDayOfWeek firstDayOfWeek)
        {
            XtraForm1 frm = new XtraForm1(patternCopy, firstDayOfWeek, this.Controller);
            frm.LookAndFeel.ParentLookAndFeel = this.LookAndFeel;
            frm.ShowExceptionsRemoveMsgBox = this.Controller.AreExceptionsPresent();
            return frm;
        }
    }
}
vb
Imports DevExpress.XtraScheduler.UI
Imports System

Namespace E558
    Partial Public Class HourRecurrenceControl
        Inherits RecurrenceControlBase

        Public Sub New()
            MyBase.New()
            InitializeComponent()
            Me.UpdateControlsCore()
            Me.SubscribeControlsEvents()

        End Sub
        Protected Overrides Sub SubscribeControlsEvents()
            MyBase.SubscribeControlsEvents()
            AddHandler spinEdit1.EditValueChanged, AddressOf spinEdit1_EditValueChanged
        End Sub
        Protected Overrides Sub UnsubscribeControlsEvents()
            MyBase.UnsubscribeControlsEvents()
            RemoveHandler spinEdit1.EditValueChanged, AddressOf spinEdit1_EditValueChanged
        End Sub

        Private Sub spinEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
            MyBase.RecurrenceInfo.Periodicity = MyBase.Validator.GetIntegerValue(Me.spinEdit1.EditValue)
        End Sub
        Protected Overrides Sub UpdateControlsCore()
            MyBase.UpdateControlsCore()
            Me.spinEdit1.EditValue = MyBase.RecurrenceInfo.Periodicity
        End Sub
    End Class
End Namespace
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
Imports System

Namespace E558
    Partial Public Class XtraForm1
        Inherits AppointmentRecurrenceForm

        Public Sub New(ByVal pattern As Appointment, ByVal fdow As FirstDayOfWeek, ByVal afc As AppointmentFormController)
            MyBase.New(pattern, fdow, afc)
            'InitializeComponent();
            checkEdit1.Tag = RecurrenceType.Hourly
            UnsubscribeRecurrenceTypeControlsEvents()
            SubscribeRecurrenceTypeControlsEvents()
            SetRecurrenceType(Me.GetRecurrenceType())
        End Sub

        Protected Overrides Sub InitializeControls(ByVal firstDayOfWeek As FirstDayOfWeek)
            InitializeComponent()
            MyBase.InitializeControls(firstDayOfWeek)
        End Sub

        Protected Overrides Sub SubscribeRecurrenceTypeControlsEvents()
            MyBase.SubscribeRecurrenceTypeControlsEvents()
            If checkEdit1 IsNot Nothing Then
                AddHandler checkEdit1.EditValueChanged, AddressOf chkRecurrenceTypeChanged
            End If
        End Sub
        Protected Overrides Sub UnsubscribeRecurrenceTypeControlsEvents()
            MyBase.UnsubscribeRecurrenceTypeControlsEvents()
            If checkEdit1 IsNot Nothing Then
                RemoveHandler checkEdit1.EditValueChanged, AddressOf chkRecurrenceTypeChanged
            End If
        End Sub
        Protected Overrides Sub ChangeCurrentRecurrenceControl()
            If Me.CurrentRecurrenceControl IsNot Nothing Then
                Me.CurrentRecurrenceControl.Visible = False
            End If
            Select Case Me.GetRecurrenceType()
                Case RecurrenceType.Daily
                    Me.CurrentRecurrenceControl = Me.dailyRecurrenceControl1

                Case RecurrenceType.Weekly
                    Me.CurrentRecurrenceControl = Me.weeklyRecurrenceControl1

                Case RecurrenceType.Monthly
                    Me.CurrentRecurrenceControl = Me.monthlyRecurrenceControl1
                Case RecurrenceType.Hourly
                    Me.CurrentRecurrenceControl = Me.hourRecurrenceControl1

                Case Else
                    Me.CurrentRecurrenceControl = Me.yearlyRecurrenceControl1
            End Select

            Me.CurrentRecurrenceControl.Visible = True

        End Sub
        Protected Overrides Sub SetRecurrenceType(ByVal type As RecurrenceType)
            If type = RecurrenceType.Hourly AndAlso checkEdit1 IsNot Nothing Then
                checkEdit1.Checked = True
                Return
            End If
                MyBase.SetRecurrenceType(type)
        End Sub
    End Class
End Namespace
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
Imports System.Windows.Forms

Namespace E558
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
            AddHandler schedulerControl1.EditAppointmentFormShowing, AddressOf schedulerControl1_EditAppointmentFormShowing
        End Sub

        Private Sub schedulerControl1_EditAppointmentFormShowing(ByVal sender As Object, ByVal e As AppointmentFormEventArgs)
            Using frm = New MyAppointmentForm(TryCast(sender, SchedulerControl), e.Appointment, e.OpenRecurrenceForm)
                e.DialogResult = frm.ShowDialog()
            End Using
            e.Handled = True
        End Sub
    End Class
    Public Class MyAppointmentForm
        Inherits AppointmentForm

        Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment)
            MyBase.New(control, apt)
        End Sub
        Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment, ByVal openRecurrenceForm As Boolean)
            MyBase.New(control, apt, openRecurrenceForm)
        End Sub
        Protected Overrides Function CreateAppointmentRecurrenceForm(ByVal patternCopy As Appointment, ByVal firstDayOfWeek As FirstDayOfWeek) As Form
            Dim frm As New XtraForm1(patternCopy, firstDayOfWeek, Me.Controller)
            frm.LookAndFeel.ParentLookAndFeel = Me.LookAndFeel
            frm.ShowExceptionsRemoveMsgBox = Me.Controller.AreExceptionsPresent()
            Return frm
        End Function
    End Class
End Namespace

Implements

IXtraResizableControl

Inheritance

Show 13 items

Object MarshalByRefObject Component Control ScrollableControl ContainerControl UserControl XtraUserControl RecurrenceControlBase DailyRecurrenceControl

MonthlyRecurrenceControl

WeeklyRecurrenceControl

YearlyRecurrenceControl

See Also

RecurrenceControlBase Members

How to: Create Appointments with Various Recurrence Types Programmatically

DevExpress.XtraScheduler.UI Namespace