Skip to main content Skip to footer

Modifying Appointment Dialog in C1Schedule for Winforms

As of now, when we talk about customization of Appointment Edit Dialog box in C1Schedule for Winforms, we think of creating a new editing form from scratch. But is there any way we can customize the existing Appointment editing box? For example, I want to add a new button besides the Delete button in the Appointment edit box or I don't want the reminder checkbox to be checked by default. Answer to the above question is Yes!!! If we study the class defined for Appointment Edit dialog box, it is nothing but a Windows form. All the buttons, checkboxes, textboxes, e.t.c. are part of control collection of this form. So I think you might have guessed what the trick is behind this blog. All the controls in the appointment edit box are grouped into either a part of a Panel or a toolbar control. You simply have to get to these Panels or Toolbars and add the desired control or remove it from its collection. But this is not the only complete solution. When an appointment box opens, you do not have access to the Appointment edit box. So how can you edit this appointment box? To do so, you have to cancel the existing display of Appointment editing box and then show a new Appointment box mapped to the current appointment object. You can then loop through the structure of this appointment box and do the desired modifications. Lets see the flow of code for the above implementation.

Define the temporary variables

' Flag to determine whether the appointment box is used  
' for creating or modifying an appointment  
Dim newEditingStatus As Boolean = False  

' refers to the appointment being modified  
Dim currentAppointment As C1.C1Schedule.Appointment  

' refers to the user defined Appointment Form  
Dim _customAppointmentForm As C1.Win.C1Schedule.Forms.AppointmentForm

Cancel the existing Appointment and create a new Appointment editing Form

We can implement this in either or both of the following events depending upon the usage.

  • BeforeAppointmentCreate
  • BeforeAppointmentShow

So, here is the code for both BeforeAppointmentCreate event and BeforeAppointmentShow events.

    Private Sub C1Schedule1_BeforeAppointmentCreate(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles C1Schedule1.BeforeAppointmentCreate  

        e.Cancel = True  

        currentAppointment = New C1.C1Schedule.Appointment  
        currentAppointment.Start = Me.C1Schedule1.SelectedInterval.Start  
        currentAppointment.End = Me.C1Schedule1.SelectedInterval.End  
        Me.C1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(currentAppointment)  

        _customAppointmentForm = New C1.Win.C1Schedule.Forms.AppointmentForm(Me.C1Schedule1, currentAppointment)  
        AddHandler \_customAppointmentForm.FormClosing, AddressOf CustomAppointmentForm\_FormClosing  

        ' it defines whether the current Appointment box  
        ' will open for new Appointment or modifying an appointment  
        newEditingStatus = True  

        ModifyForm(_customAppointmentForm)  

        _customAppointmentForm.ShowDialog(Me)  

    End Sub  

    Private Sub C1Schedule1_BeforeAppointmentShow(sender As Object, e As C1.C1Schedule.CancelAppointmentEventArgs) Handles C1Schedule1.BeforeAppointmentShow  

        e.Cancel = True  

        Me.C1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(e.Appointment)  

        _customAppointmentForm = New C1.Win.C1Schedule.Forms.AppointmentForm(Me.C1Schedule1, e.Appointment)  
        AddHandler \_customAppointmentForm.FormClosing, AddressOf CustomAppointmentForm\_FormClosing  

        ModifyForm(_customAppointmentForm)  

        _customAppointmentForm.ShowDialog(Me)  

    End Sub  

Define the method to modify the Appointment Form

In the above code snippet, you can see the use of ModifyForm() method. This method implements the code to make the changes in the appointment form.


     Public Sub ModifyForm(ByRef _appform As C1.Win.C1Schedule.Forms.AppointmentForm)  

        ' Loop through the controls to do the modifications  
        For i As Integer = _appform.Controls.Count - 1 To 0 Step -1  
            Dim c As Control = _appform.Controls(i)  
            If c.GetType() = GetType(Panel) Then  
                For j As Integer = c.Controls.Count - 1 To 0 Step -1  
                    Dim d As Control = c.Controls(j)  
                    If d.GetType() = GetType(CheckBox) Then  

                        ' Uncheck the reminder check box while  
                        ' creating a new appointment  
                        If d.Name = "chkReminder" Then  
                            If newEditingStatus = True Then  
                                CType(d, CheckBox).Checked = False  

                            End If  

                        End If  
                    End If  
                Next  
            ElseIf c.GetType() = GetType(ToolStrip) Then  

                ' Add a new custom button  
                If c.Name.Equals("toolStrip1") Then  
                    Dim btn As New ToolStripButton()  
                    btn.Text = "New Button"  
                    AddHandler btn.Click, AddressOf CustomButton_Click  
                    CType(c, ToolStrip).Items.Add(btn)  
                End If  

                For j As Integer = 0 To CType(c, ToolStrip).Items.Count - 1  
                    Dim d As ToolStripItem = CType(c, ToolStrip).Items(j)  
                    If d.GetType() = GetType(ToolStripButton) Then  
                        If d.Name = "btnSave" Then  
                            AddHandler CType(d, ToolStripButton).Click, AddressOf SaveButton_Click  
                        End If  
                    End If  
                Next  
            End If  
        Next  

    End Sub  

Functions to be used as handler for the custom button


    Private Sub CustomButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  

        If Not currentAppointment Is Nothing Then  
            MessageBox.Show("This is a new button Action box")  
        End If  

    End Sub  

    Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  

        Dim app As Appointment = CType(CType(sender, ToolStripButton).Owner.FindForm(), C1.Win.C1Schedule.Forms.AppointmentForm).Appointment  
        C1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(app)  
    End Sub  

Reset the new appointment status variable


    Public Sub CustomAppointmentForm_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)  
        newEditingStatus = False  
    End Sub  

Download the complete sample from the links below. Download C# Sample Download VB Sample

MESCIUS inc.

comments powered by Disqus