Home

Win32 Controls: The Split Button

   

Introduction

A split button is made of two parts separated by a vertical line (a separator). The left side behaves like a normal button. The right sides shows a down-pointing button. When clicked, that right part can show a popup menu. Of course, the popup menu must have been previously created.

 

To create a split button, set the button's Style to bsSplitButton:

Split Button

Of course, you have the option of using a picture. This is done by creating an image list, assigning it to the button, and specifying an image index. You can position the picture in any of the ImageAlignment positions.

 

The Popup Menu

The most significant aspect of a split button is its ability to show a menu when the down-pointing button is clicked. You must first create a popup menu but not assign it to the PopupMenu property of the button. After creating a popup menu, to let you assign it to a button, the the TCustomButton class is equipped with a property named DropDownMenu:

__property Menus::TPopupMenu * DropDownMenu = 
{
	read=FDropDownMenu,
	write=SetDropDownMenu
};

To visuall specify the menu that would display when the down-pointing button is clicked, access the Object Inspector for the button and, in the DropDownMenu, select the created popup menu.

To give you the ability to deal with the down-pointing button, the TCustomButton class provides the OnDropDownClick event, which is of type TNotifyEvent:

__property TNotifyEvent OnDropDownClick;

You can use this event to specify that the popup menu must display when the down-pointing button is clicked. This can be done as follows:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1DropDownClick(TObject *Sender)
{
	Button1->DropDownMenu = PopupMenu1;
}
//---------------------------------------------------------------------------
 

 

 
 

Home Copyright © 2010-2016, FunctionX