Xceed Grid for WinForms v4.3 Documentation
Welcome to Xceed Grid for WinForms v4.3 / Basic Concepts / Editor Controls / Using the controls at design-time

In This Topic
    Using the controls at design-time
    In This Topic

    The editor controls can be used in a Windows Forms application outside of the grid. These include the WinButton, WinCalculator, WinCalendar, WinCheckBox, WinDatePicker, WinHorizontalScrollBar, WinNumericTextBox, WinPanel, WinTextBox, and WinVerticalScrollBar controls. This topic explains how to use them using the designer.

    Adding the controls to a form

    Once Xceed Grid for WinForms has been installed, the editor controls can be added to a form by double-clicking on the desired control, or dragging the desired control onto the form.

    Each control provides a standard behavior when it is dropped on a form, allowing the control to be used immediately, without any modifications or code being required. For example, the WinCalendar control, by default, includes a "Today" and "None" button, displays the present (DateTime.Today), selected and current dates, in addition to allowing navigation between multiple months. 

    Once a control has been dropped onto a form, its various properties can be set via the property grid to add to or modify the default, standard behavior. Most modifications made to the controls at design-time will automatically be reflected in the control. For example, in the image below, the PreviewDaysBackColor property of the WinCalendar control has been changed from its default value to the system's InactiveCaptionText color. 

    To reduce the size of the image below, not all properties are displayed in the property grid. 

    Handling events

    In C#, the events provided by each control can be accessed via the property grid, and the event declarations can be added to your code by double-clicking on the event to handle. For example, in the image below, 2 labels have been added to the form below the WinCalendar control. The first label will be used to display the selected date and is named "labelSelectedDate". The second label will be used to display the current date and is named "labelCurrentDate". To update the labels when the dates change, the SelectedDateChanged (winCalendar1_SelectedDateChanged) and CurrentDateChanged (winCalendar1_CurrentDateChanged) events have been handled. 

    To reduce the size of the image below, not all events are displayed in the property grid.

    In Visual Basic .NET, events are not accessible via the property grid. Therefore, they must be subscribed to via code using the AddHandler/AddressOf operators. A demonstration of even handling is also available in the Demos and Tutorials topic.

    VB.NET Copy Code

    ' In the form's Load event
    AddHandler WinCalendar1.SelectedDateChanged, AddressOf Me.Calendar_SelectedDateChanged
    AddHandler WinCalendar1.CurrentDateChanged, AddressOf Me.Calendar_CurrentDateChanged

    The following code is used in the SelectedDateChanged and CurrentDateChanged event handlers to update the labels displayed on the form.

    VB.NET
    Copy Code
    Private Sub Calendar_SelectedDateChanged(ByVal sender As Object, _
                                             ByVal e As Xceed.Editors.SelectedDateCHangedEventArgs)
      Dim selectedDate As DateTime = CType(sender, Xceed.Editors.WinCalendar).SelectedDate
      labelSelectedDate.Text = "Selected Date : " + selectedDate.ToString("dddd, MMMM d, yyyy")
    End Sub
    Private Sub Calendar_CurrentDateChanged(ByVal sender As Object, _
                                            ByVal e As Xceed.Editors.CurrentDateChangedEventArgs)
      Dim currentDate As DateTime = CType(sender, Xceed.Editors.WinCalendar).CurrentDate
      labelCurrentDate.Text = "Current Date : " + currentDate.ToString("dddd, MMMM d, yyyy")
    End Sub
    C#
    Copy Code
    private void winCalendar1_SelectedDateChanged(object sender,
                                                  Xceed.Editors.SelectedDateChangedEventArgs e)
    {
      DateTime selectedDate = ( ( WinCalendar )sender ).SelectedDate;
      labelSelectedDate.Text = "Selected Date : " + selectedDate.ToString( "dddd, MMMM d, yyyy" );
    }
    private void winCalendar1_CurrentDateChanged(object sender,
                                                 Xceed.Editors.CurrentDateChangedEventArgs e)
    {
      DateTime currentDate = ( ( WinCalendar )sender ).CurrentDate;
      labelCurrentDate.Text = "Current Date : " + currentDate.ToString( "dddd, MMMM d, yyyy" );
    }

    Embedding controls

    The WinCalendar, WinComboBox, WinDatePicker, WinPanel, and WinTextBox controls are container controls into which any other control can be added. To add a child control to one of the container controls, the container control must be added and selected on the form. Once the container control is selected, choose the child control in the toolbox and double-click on it, or drag it to the container control. 

    A control that is added to one of the container controls is added to the container's Controls collection. If a WinButton control is added to a WinComboBox, WinDatePicker, or WinTextBox control, it will be added to both the SideButtons collection and the Controls collection.