Skip to content

TStyledToolButton ​

ComponentDescription
TStyledToolButtonTStyledToolButton is the button of the TStyledToolbar: a styled graphic button (no window handle, no keyboard focus) with the behaviour of the TToolButton: push button, check button, drop-down button, separator and divider.

Unit: Vcl.StyledToolbar. Inheritance: TGraphicControl > TCustomStyledGraphicButton > TStyledToolButton. Platforms: Win32 and Win64.

When to use it ​

Use it inside a TStyledToolbar in place of TToolButton. The button takes from the toolbar the images, the size, the style (Family/Class/Appearance, shape, radius), the cursor and the Flat / ShowCaptions / List settings, and you can override any of them on a single button.

Differences from the VCL TToolButton ​

AspectTToolButtonTStyledToolButton
ParentTToolBarTStyledToolbar
Sizewidth from the captionButtonWidth x ButtonHeight of the toolbar (or its own Width)
LookVCL Style / themeFamily / Class / Appearance, shape, five state attributes (ButtonStyleNormal...), notification badge
StylestbsButton, tbsCheck, tbsDropDown, tbsSeparator, tbsDivider, tbsTextButtonthe same, except tbsTextButton (raises an exception when assigned)
Radio groupGrouped (+ Marked)Grouped with Style = tbsCheck (Marked is only stored, for compatibility)
MenuMenuItem, DropdownMenuMenuItem, DropDownMenu and the OnDropDownClick event
Wrapwraps the toolbar rowpublished as the WordWrap of the caption

Button styles (Style) ​

ValueBehaviour
tbsButtonnormal push button (default)
tbsChecktoggle button: stays pressed (Down) after the click; with Grouped the buttons of the same group work as radio buttons
tbsDropDownsplit button: the arrow shows the DropDownMenu; its width is ButtonWidth plus the width of the arrow
tbsSeparatorempty space (default width 6)
tbsDividerlike the separator, used as a visual division between groups

A separator or divider is always disabled, has no image and no caption, and its width is not forced to ButtonWidth.

Style inheritance ​

StyleFamily, StyleClass, StyleAppearance, StyleDrawType, StyleRadius, StyleShadowSize, Images and Flat are copied from the toolbar when the button is inserted, and they follow the toolbar when it changes as long as the button has the same value of the toolbar. Assign a different value to the button to override it. The values equal to the ones of the toolbar are not saved in the .dfm.

Caption is drawn only if the toolbar has ShowCaptions = True. With captions the image is placed according to ImageAlignment (default iaTop); with List = True it goes on the left (on the right in right-to-left); without captions it is centered.

Design-time use and Component Editor ​

Select a button and right-click it: Styled Button Editor... opens the Component Editor to choose Family/Class/Appearance and shape of the single button. To add buttons use the verbs of the toolbar (Add StyledToolbar Button, Add StyledToolbar Separator). ImageIndex and ImageName (Delphi 10.4+) have the usual image property editors.

Examples ​

Push button with image and event:

pascal
if Toolbar.NewButton(LButton) then
begin
  LButton.Caption := 'Save';
  LButton.ImageIndex := 5;
  LButton.Hint := 'Save file';
  LButton.ShowHint := True;
  LButton.OnClick := SaveClick;
end;

Check button:

pascal
if Toolbar.NewButton(LBold, tbsCheck) then
begin
  LBold.Caption := 'B';
  LBold.AllowAllUp := True;
  LBold.OnClick := BoldClick;   //read LBold.Down inside the handler
end;

Radio group of check buttons (only one is down):

pascal
for I := 0 to 2 do
  if Toolbar.NewButton(LButton, tbsCheck) then
  begin
    LButton.Grouped := True;
    LButton.Caption := Format('Align %d', [I]);
    LButton.ImageIndex := 10 + I;
  end;
Toolbar.Buttons[0].Down := True;

Drop-down button:

pascal
if Toolbar.NewButton(LButton, tbsDropDown) then
begin
  LButton.Caption := 'File';
  LButton.DropDownMenu := FilePopupMenu;
  LButton.OnDropDownClick := FileDropDownClick;  //before the menu is shown
end;

Separator and notification badge:

pascal
Toolbar.NewButton(LSep, tbsSeparator);

if Toolbar.NewButton(LButton) then
begin
  LButton.ImageIndex := 10;
  LButton.NotificationBadge.NotificationCount := 5;
  LButton.NotificationBadge.Color := clRed;
end;

Single button with its own style:

pascal
LButton.SetButtonStyle(BOOTSTRAP_FAMILY, btn_danger, BOOTSTRAP_NORMAL);

More examples in StyledToolbar-Examples.

Demo and reference ​

See also ​

Released under Apache License, Version 2.0.