Xceed Grid for WinForms v4.3 Documentation
WinButton control

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Editor Controls > WinButton control

The WinButton class represents an extensible and themable button control for Windows Forms which can be used as a regular button, an embeddable button, or a button to drop-down any type of control. It supports both Windows XP and classic Windows themes and can adapt to the current Windows theme. Several button types are supported to offer a wide variety of UI behaviors, including toolbars, chevrons, etc. The WinButton control can be embedded into other Xceed editors to create custom controls. 

Button types

The WinButton control offers a predefined set of the most commonly sought-after buttons, including toolbar buttons, chevrons and window buttons. In order to change the appearance of a button, an instance of the ButtonType class must be assigned to the button's ButtonType property.

VB.NET
Copy Code
' Change the appearance of the button.

WinButton1.ButtonType = New ButtonType( Xceed.Editors.ButtonBackgroundImageType.Close, _

                                        Xceed.Editors.ButtonImageType.VerticalChevron )
C#
Copy Code
// Change the appearance of the button.

winButton1.ButtonType = new ButtonType( Xceed.Editors.ButtonBackgroundImageType.Close,

                                        Xceed.Editors.ButtonImageType.VerticalChevron );

With the WinButton control, it is also possible to set a custom image for both the background and the foreground images. To set custom background and foreground images, an instance of the ButtonType property must be initialized with both BackgroundImageType and ImageType set to User. As a result, the image assigned to the button's BackgroundImage property will be used as the button's background image, and the image assigned to the button's Image property will be used as the button's foreground image.

VB.NET
Copy Code
' Create an instance of the ButtonType class with both BackgroundImageType and

' ImageType set to User.

Dim buttonType As New Xceed.Editors.ButtonType( Xceed.Editors.ButtonBackgroundImageType.User, _

                                                Xceed.Editors.ButtonImageType.User )

' Assign the new instance of the ButtonType class to the button's ButtonType property.

WinButton1.ButtonType = buttonType

' Use the images assigned to the button's BackgroundImage and Image properties as the

' background and foreground images.

WinButton1.BackgroundImage = New Bitmap( " C:\ Images\background.gif " )

WinButton1.Image = New Bitmap( " C :\ Images\foreground.gif " )
C#
Copy Code
// Create an instance of the ButtonType class with both BackgroundImageType and

// ImageType set to User.

ButtonType buttonType = new Xceed.Editors.ButtonType( Xceed.Editors.ButtonBackgroundImageType.User,

                                                      Xceed.Editors.ButtonImageType.User );

// Assign the new instance of the ButtonType class to the button's ButtonType property.

winButton1.ButtonType = buttonType;

// Use the images assigned to the button's BackgroundImage and Image properties

// as the background and foreground images.

winButton1.BackgroundImage = new Bitmap( " C :\\Images\\background.gif" );

winButton1.Image = new Bitmap( " C :\\Images\\foreground.gif" );

Embedded buttons

The WinButton control can be embedded into the WinCalendar, WinComboBox, WinDatePicker, WinTextBox, and WinPanel controls to expand on existing controls and create completely customized controls. 

 

Embedded buttons can be added to the left or right (default) of container controls other than WinPanel and WinCalendar controls via the SideButtons property. Buttons added to the WinPanel and WinCalendar controls can be located anywhere within the container and are added via the Controls.Add( ) method.

VB.NET
Copy Code
' Add an embedded default button to the right of the date picker.

WinDatePicker1.SideButtons.Add( New WinButton( "..." ) )

' Add another embedded button to the left of the date picker

Dim button As New WinButton( New ButtonType( ButtonBackgroundImageType.Combo, _

                                             ButtonImageType.ScrollUp ) )

button.Dock = DockStyle.Left

WinDatePicker1.SideButtons.Add( button )
C#
Copy Code
// Add an embedded default button to the right of the date picker.

winDatePicker1.SideButtons.Add( new WinButton( "..." ) );

// Add another embedded button to the left of the date picker.

WinButton button = new WinButton( new ButtonType( ButtonBackgroundImageType.Combo,

                                                  ButtonImageType.ScrollUp ) );

button.Dock = DockStyle.Left;

winDatePicker1.SideButtons.Add( button );

Dropdown buttons

The WinButton and WinTextBox controls, as well as every control that derives from the WinTextBox class, have a DropDownControl property to which a control can be assigned. In the case of the WinButton, this will result in the dropdown being opened when the button is pressed (or when the OpenDropDown method is called or the DroppedDown property is set to true). For the WinTextBox control and its derivatives, the dropdown will be opened when the OpenDropDown method is called, the DroppedDown property is set to true, or when the DropDownButton associated with the control is pressed. 

When a control's OpenDropDown method is called, the dropdown that is opened will be aligned with its parent control. For example, in the first image below, the dropdown is associated with the embedded button, and the button's OpenDropDown method is called to open the dropdown. This will result in the dropdown being aligned with its immediate parent control (the button) and not with the container WinTextBox.  

On the other hand, if the dropdown is associated with the WinTextBox and the textbox's OpenDropDown method is called, the dropdown will be aligned instead with the textbox since it is its immediate parent.  

The same kind of alignment would occur if the embedded button was set as the textbox's DropDownButton, since the button would open the dropdown associated with its parent rather than its own. 

The drop-down direction of the dropdown can be changed via the control's DropDownDirection property. If the DropDownDirection property is set to Up or Down the dropdown will open above or below the control. If it is set to Automatic (default), the dropdown will open below the control if enough space is available or above if there is not enough space below.

AutoSizeMode property

The AutoSizeMode property indicates if the size of the WinButton control should automatically be adjusted according to specific system defined values. If set to AutoSizeMode.None (default), the size of the WinButton control will be determined by its Width and Height properties. If set to AutoSizeMode.ScrollBarWidth, the width will automatically be adjusted to correspond to the scrollbar width defined by SystemInformation.VerticalScrollBarWidth. If set to AutoSizeMode.ScrollBarHeight, the height will automatically be adjusted to correspond to the scrollbar height defined by SystemInformation.HorizontalScrollBarHeight. If set to AutoSizeMode.ScrollBarWidthAndHeight, both the width and the height will be adjusted. 

If the WinButton control is part of the SideButtons collection of a WinTextBox (or derived) control, and is assigned as the WinTextBox control's DropDownButton, the default value of the AutoSizeMode property will be AutoSizeMode.ScrollBarWidth.