Skip to content

TStyledButtonGroup - Technical Reference ​

Overview ​

TStyledButtonGroup extends TButtonGroup with styled button rendering, per-item styles, caption/image alignment and notification badges. This page lists the members added by the library to TStyledButtonGroup, TStyledGrpButtonItem and TStyledGrpButtonItems; the members inherited from the VCL are summarized briefly. For the usage see TStyledButtonGroup.

Class Hierarchy ​

TButtonGroup            (Vcl.ButtonGroup)
  └─ TStyledButtonGroup

TGrpButtonItem          (Vcl.ButtonGroup, a TCollectionItem)
  └─ TStyledGrpButtonItem

TGrpButtonItems
  └─ TStyledGrpButtonItems

Unit ​

pascal
Vcl.StyledButtonGroup

Description ​

TStyledButtonGroup maintains the compatibility with TButtonGroup (Items, ItemIndex, ButtonOptions, ButtonWidth, ButtonHeight, Images, the VCL events) and draws every button with the Styled Components renderer. The group has a style (StyleFamily/StyleClass/StyleAppearance, shape and radius) shared by its buttons; each item can override it. The class is registered for Win32 and Win64 and has the Component Editor Styled ButtonGroup Editor... (see Component Editor).

Key Features ​

  • Full TButtonGroup compatibility
  • Group style and per-item style
  • Caption alignment (left, center, right) and image alignment (left, right, top, bottom, center), with Spacing and ImageMargins
  • Flat appearance
  • Notification badges through an event
  • Follows the VCL Style with the Classic family (AsVCLComponent)

Published properties (Object Inspector) ​

Items and layout ​

PropertyTypeDefaultDescription
ItemsTStyledGrpButtonItemsemptyCollection of the buttons (TStyledGrpButtonItem); Items.Add returns a TStyledGrpButtonItem, Items[Index] returns the VCL type TGrpButtonItem
CaptionAlignmentTAlignmenttaLeftJustifyAlignment of the caption: taLeftJustify, taCenter, taRightJustify (used when gboShowCaptions is in ButtonOptions)
ImageAlignmentTImageAlignmentiaLeftPosition of the image: iaLeft, iaRight, iaTop, iaBottom, iaCenter
ImageMarginsTImageMarginsLeft=2Margins around the image; stored only when changed
SpacingInteger4Distance between the image and the caption
FlatBooleanFalseFlat buttons: the face of the Normal and Disabled button is not drawn
ButtonsCursorTCursorcrHandPointCursor when the mouse is over a button
CursorTCursorcrDefaultCursor of the group outside the buttons

Style ​

PropertyTypeDefaultDescription
StyleFamilyTStyledButtonFamilyClassicStyle family of the buttons
StyleClassTStyledButtonClassWindowsStyle class of the buttons
StyleAppearanceTStyledButtonAppearanceNormalAppearance of the buttons
StyleDrawTypeTStyledButtonDrawTypebtRoundRectShape (btRect, btRoundRect, btRounded, btEllipse)
StyleRadiusInteger6Corner radius; must be greater than zero
StyleShadowSizeInteger-1Shadow of the buttons in pixels, the same in every state (-1 = the one of the style family, 0 = none); values below -1 raise an exception
StyleRoundedCornersTRoundedCornersall fourWhich corners are rounded
ButtonStyleNormal, ButtonStylePressed, ButtonStyleSelected, ButtonStyleHot, ButtonStyleDisabledTStyledButtonAttributesfrom the styleColors, border and font of each state, shared by the items that have the style of the group

Setting StyleFamily to a family that is not registered raises EStyledAttributesException (while streaming a form it falls back to Classic).

Events ​

EventTypeDescription
OnGetNotificationBadgeInfoTGetButtonGroupBadgeInfoSupplies the badge of an item: (const AButtonItemIndex: Integer; var ABadgeContent: string; var ASize: TNotificationBadgeSize; var APosition: TNotificationBadgePosition; var AColor, AFontColor: TColor; var AFontStyle: TFontStyles). The badge is drawn if ABadgeContent is not empty (defaults: nbsNormal, nbpTopRight, bold)

Inherited from TButtonGroup (summary) ​

ButtonOptions (gboAllowReorder, gboFullSize, gboGroupStyle, gboShowCaptions), ButtonWidth, ButtonHeight, ItemIndex, Images, Align, Anchors, Color, Font, Enabled, Visible, StyleElements, TabOrder, TabStop, PopupMenu, ShowHint, bevel/border properties, and the events OnButtonClicked, OnBeforeDrawButton, OnDrawButton, OnAfterDrawButton, OnDrawIcon, OnHotButton, OnReorderButton, OnClick, OnEnter, OnExit... See the Embarcadero documentation of Vcl.ButtonGroup.TButtonGroup.

Public members ​

MemberDescription
property AsVCLComponent: BooleanTrue when the group follows the VCL Style (Classic family, seClient in StyleElements, class equal to the active style); setting it to True resets the style to Classic/Windows/Normal. Not stored
property StyleApplied: BooleanTrue when the style has been resolved
constructor CreateStyled(AOwner; const AFamily; const AClass; const AAppearance)Creates the group with a given style (Create uses the defaults registered with RegisterDefaultRenderingStyle)
class procedure RegisterDefaultRenderingStyle(const ADrawType; const AFamily = DEFAULT_CLASSIC_FAMILY; const AClass = DEFAULT_WINDOWS_CLASS; const AAppearance = DEFAULT_APPEARANCE; const AStyleRadius = DEFAULT_RADIUS; const AButtonsCursor = DEFAULT_CURSOR)Default style, shape, radius and buttons cursor of the groups created afterwards
procedure SetButtonGroupStyle(const AStyleFamily; const AStyleClass; const AStyleAppearance)Sets family, class and appearance together; raises EStyledButtonGroupError if the combination is not available
function StyledButtonState(const AIndex: Integer; const AState: TButtonDrawState): TStyledButtonStateConverts the draw state of the VCL into the styled state (Disabled, Hot, Pressed, Selected, Normal)
procedure Assign(Source: TPersistent)Copies also the style of another TStyledButtonGroup
procedure SetBounds(...)Override of TControl.SetBounds

TStyledGrpButtonItem ​

Item of the group (Items), a TGrpButtonItem: Caption, ImageIndex, Hint, Action, OnClick are inherited from the VCL. A new item gets the style, shape and radius of the group.

Published ​

PropertyTypeDefaultDescription
ButtonGroupTStyledButtonGroupread-onlyThe group the item belongs to
StyleFamilyTStyledButtonFamilyof the groupFamily of the item; stored only if the item has a family, class or appearance different from the group
StyleClassTStyledButtonClassof the groupClass of the item
StyleAppearanceTStyledButtonAppearanceof the groupAppearance of the item
StyleDrawTypeTStyledButtonDrawTypeof the groupShape of the item; stored only if different
StyleRadiusIntegerof the groupCorner radius of the item; stored only if different
StyleShadowSizeIntegerof the groupShadow of the item (-1 = the one of the style family); stored only if different
StyleRoundedCornersTRoundedCornersof the groupRounded corners of the item; stored only if different

The item has no NotificationBadge property: the badges of the group are supplied by the OnGetNotificationBadgeInfo event of the group.

Public ​

MethodDescription
procedure SetButtonStyle(const AStyleFamily; const AStyleClass; const AStyleAppearance)Sets family, class and appearance of the item. An empty value keeps the current one or, if the item has none, uses that of the group; raises EStyledButtonGroupError if the combination is not available

TStyledGrpButtonItems ​

Collection of the items: function Add: TStyledGrpButtonItem and property ButtonGroup: TStyledButtonGroup (the owner). Class references: TStyledButtonGroupClass, TStyledGrpButtonItemClass, TStyledGrpButtonItemsClass.

Types ​

NameDescription
TGetButtonGroupBadgeInfoType of OnGetNotificationBadgeInfo (see above)
TGrpButtonProcreference to procedure (Button: TStyledGrpButtonItem), used to iterate the items
EStyledButtonGroupErrorException class

Usage Examples ​

Basic ButtonGroup ​

pascal
var
  Group: TStyledButtonGroup;
  Item: TStyledGrpButtonItem;
begin
  Group := TStyledButtonGroup.CreateStyled(Self,
    BOOTSTRAP_FAMILY, btn_primary, BOOTSTRAP_NORMAL);
  Group.Parent := Self;
  Group.Align := alLeft;
  Group.Images := ImageList1;
  Group.ButtonOptions := [gboFullSize, gboShowCaptions];

  Item := Group.Items.Add;
  Item.Caption := 'Home';
  Item.ImageIndex := 0;
end;

Image above the caption ​

pascal
Group.SetButtonGroupStyle(ANGULAR_LIGHT_FAMILY, btn_PrimaryIndigo, RaisedAttr);
Group.ImageAlignment := iaTop;
Group.CaptionAlignment := taCenter;
Group.ButtonOptions := [gboShowCaptions, gboGroupStyle];
Group.ButtonHeight := 80;

Per-item styling ​

pascal
TStyledGrpButtonItem(Group.Items[0]).StyleClass := btn_primary;   // blue
TStyledGrpButtonItem(Group.Items[1]).StyleClass := btn_success;   // green
TStyledGrpButtonItem(Group.Items[2]).StyleClass := btn_danger;    // red

Flat group ​

pascal
Group.Flat := True;
Group.CaptionAlignment := taLeftJustify;
Group.ImageAlignment := iaLeft;

Replacing TButtonGroup with the Interposer unit ​

Vcl.StyledComponentsHooks declares TButtonGroup = class(TStyledButtonGroup); the group creates TStyledGrpButtonItem items. See Interposer Unit.

See Also ​

Released under Apache License, Version 2.0.