ButtonStyle (Delphi)
Description
Select File > New > VCL Forms Application - Delphi.
On the Tool Palette, double-click the following controls to add them to your form:
Double-click the TPopupMenu. When the Menu Designer window appears, right-click and choose Insert (or press the Ins key).
To set a name for a menu item that appears when you set the button style to bsSplitButton, click the Caption option in the Object Inspector and write the name you want to appear in the popup menu. Then double-click the form, and the Code Editor opens at the FormCreate procedure.
Code
procedure TForm2.FormCreate(Sender: TObject);
begin
//ComboBox options
ComboBox1.AddItem('bsPushButton',nil);
ComboBox1.AddItem('bsCommandLink',nil);
ComboBox1.AddItem('bsSplitButton',nil);
end;
Switch back to Design view and select the combobox. In the Object Inspector, click the Events tab. Then double-click the OnChange event handler and insert the following code into the ComboBox1Change procedure:
procedure TForm2.ComboBox1Change(Sender: TObject);
begin
//set button style when you change combobox option
if ComboBox1.ItemIndex = 0 then
Button1.Style := bsPushButton;
if ComboBox1.ItemIndex = 1 then
Button1.Style := bsCommandLink;
if ComboBox1.ItemIndex = 2 then
Button1.Style := bsSplitButton;
end;
From the Design view, select the button and double-click OnDropDownClick. Then add this code in the Button1DropDownClick procedure:
procedure TForm2.Button1DropDownClick(Sender: TObject);
begin
//when set style button to bsSplitButton set DropDownMenu
Button1.DropDownMenu := PopupMenu1;
end;