ComponentOne CalendarView for WinForms
CalendarView for WinForms / Quick Start
In This Topic
    Quick Start
    In This Topic

    This quick start gets you started with the CalendarView and the DateEdit control by letting you create a WinForms application, add CalendarView and DateEdit controls to it, and input a date from CalendarView into DateEdit.

    Note that the quick start binds CalendarView to DateEdit to input a date. However, you can input a date into DateEdit directly from DateEdit's calendar pop-up.  

    To quickly get started using the controls, follow these steps:

    1. Add the CalendarView and the DateEdit control to the application
    2. Customize the Calendarview and the DateEdit control
    3. Input date from CalendarView into DateEdit

    The following image shows the DateEdit contol displaying today's date selected from the CalendarView control.

     

    Step 1: Add the CalendarView and the DateEdit control to the application

    1. Create a Windows Forms Application in Visual Studio.
    2. Drag and drop the C1CalendarView control from the Toolbox to the application.
    3. Drag and drop the C1DateEdit control from the Toolbox to the application.

    Step 2: Customize the CalendarView and the DateEdit control

    1. Switch to the code view.
    2. Add the following code to customize CalendarView and DateEdit with respect to location, size, and back color.
      ' set CalendarView location
      C1CalendarView1.Location = New System.Drawing.Point(300, 152)
      
      ' set CalendarView backcolor
      C1CalendarView1.Theme.Common.BackColor =
          System.Drawing.Color.FromArgb(CInt(CByte(224)),
                                        CInt(CByte(224)),
                                        CInt(CByte(224)))
      
      ' hide CalendarView
      C1CalendarView1.Visible = False
      
      ' set DateEdit size and location
      C1DateEdit1.Size = New System.Drawing.Size(150, 20)
      C1DateEdit1.Location = New System.Drawing.Point(330, 126)
      
      // set CalendarView location
      c1CalendarView1.Location = new System.Drawing.Point(300, 152);
      
      // set CalendarView backcolor
      c1CalendarView1.Theme.Common.BackColor = System.Drawing.Color.FromArgb
                                                  (((int)(((byte)(224)))),
                                                  ((int)(((byte)(224)))),
                                                  ((int)(((byte)(224)))));
      // hide CalendarView
      c1CalendarView1.Visible = false;
      
      // set DateEdit size and location
      c1DateEdit1.Size = new System.Drawing.Size(150, 20);
      c1DateEdit1.Location = new System.Drawing.Point(330, 126);
      

    Back to Top

    Step 3: Input date from CalendarView into DateEdit

    Add the following code to pop up CalendarView by clicking into DateEdit, and then select and input a date from CalendarView into the DateEdit control.

    Private Sub Form1_Load(sender As Object, e As EventArgs)
        ' handle the textbox Click event
        AddHandler c1DateEdit1.Click, AddressOf c1DateEdit1_Click
    
        ' handle the CalendarView SelectionChanged event
        AddHandler c1CalendarView1.SelectionChanged, AddressOf CalendarView_SelectionChanged
    
        c1CalendarView1.Visible = False
    
        ' hide DateEdit's calendar pop-up
        c1DateEdit1.ShowDropDownButton = False
    End Sub
    Private Sub c1DateEdit1_Click(sender As Object, e As EventArgs)
        c1CalendarView1.Visible = True
        AddHandler c1CalendarView1.SelectionChanged, AddressOf CalendarView_SelectionChanged
    End Sub
    
    Private Sub CalendarView_SelectionChanged(sender As Object, e As EventArgs)
        ' input selected date into textbox from CalendarView
        If c1CalendarView1.Visible Then
            c1DateEdit1.Text = c1CalendarView1.SelectedDates(0).ToShortDateString()
        End If
    
        ' hide CalendarView 
        c1CalendarView1.Hide()
    End Sub
    
    private void Form1_Load(object sender, EventArgs e)
    {
        // handle the textbox Click event
        c1DateEdit1.Click += c1DateEdit1_Click;
    
        // handle the CalendarView SelectionChanged event
        c1CalendarView1.SelectionChanged += CalendarView_SelectionChanged;
    
        c1CalendarView1.Visible = false;
    
        // hide DateEdit's calendar pop-up
        c1DateEdit1.ShowDropDownButton = false;
    }
    private void c1DateEdit1_Click(object sender, EventArgs e)
    {
        c1CalendarView1.Visible = true;
        c1CalendarView1.SelectionChanged += CalendarView_SelectionChanged;
    }
    
    private void CalendarView_SelectionChanged(object sender, EventArgs e)
    {
        // input selected date into textbox from CalendarView
        if (c1CalendarView1.Visible)
            c1DateEdit1.Text = c1CalendarView1.SelectedDates[0].ToShortDateString();
    
        // hide CalendarView 
        c1CalendarView1.Hide();
    }
    

    Back to Top

    See Also