Skip to content

TStyledButtonGroup Demo ​

Overview ​

This demo compares TStyledButtonGroup with the standard VCL TButtonGroup, demonstrating how to create modern button groups with individual button styling while maintaining full compatibility.

Styled ButtonGroup Demo

What You'll Learn ​

  • How to create TStyledButtonGroup dynamically
  • Adding styled button items with different styles
  • Comparison with standard TButtonGroup
  • Using notification badges on group items
  • Image and caption alignment options
  • Button sizing and layout modes

ButtonGroup Comparison ​

The demo creates button groups side-by-side:

Standard TButtonGroup (Left) ​

Shows the classic VCL TButtonGroup for comparison.

TStyledButtonGroup (Right) ​

Modern styled button group with:

  • Individual button styling (Family/Class/Appearance)
  • Per-item style customization
  • Notification badge support
  • Consistent appearance across Windows versions

Dynamic ButtonGroup Creation ​

Creating Standard ButtonGroup ​

pascal
procedure TfmStyledButtonGroup.CreateButtonGroup;
begin
  FButtonGroup := TButtonGroup.Create(Self);
  FButtonGroup.Parent := Self;
  FButtonGroup.Align := alLeft;
  FButtonGroup.ButtonOptions := [gboFullSize, gboShowCaptions];
  FButtonGroup.Images := VirtualImageList;
  FButtonGroup.ButtonWidth := BUTTON_WIDTH;
  FButtonGroup.ButtonHeight := BUTTON_HEIGHT;
end;

Creating TStyledButtonGroup ​

pascal
procedure TfmStyledButtonGroup.CreateStyledButtonGroup;
begin
  FStyledButtonGroup := TStyledButtonGroup.Create(Self);
  FStyledButtonGroup.Parent := Self;
  FStyledButtonGroup.Align := alLeft;
  FStyledButtonGroup.ButtonOptions := [gboFullSize, gboShowCaptions];
  FStyledButtonGroup.Images := VirtualImageList;
  FStyledButtonGroup.ButtonWidth := BUTTON_WIDTH;
  FStyledButtonGroup.ButtonHeight := BUTTON_HEIGHT;
end;

Adding Button Items ​

Standard Button Items ​

pascal
function TfmStyledButtonGroup.AddButtonToButtonGroup(
  var AButtonGroup: TButtonGroup;
  const ACaption: string;
  const AImageIndex: Integer): TGrpButtonItem;
begin
  Result := AButtonGroup.Items.Add;
  Result.Caption := ACaption;
  Result.Hint := Format('Hint of %s button.', [ACaption]);
  Result.ImageIndex := AImageIndex;
end;

Styled Button Items ​

pascal
function TfmStyledButtonGroup.AddStyledButtonToButtonGroup(
  var AButtonGroup: TStyledButtonGroup;
  const ACaption: string;
  const AImageIndex: Integer;
  const AFamily: TStyledButtonFamily;
  const AClass: TStyledButtonClass;
  const AAppearance: TStyledButtonAppearance): TStyledGrpButtonItem;
begin
  Result := AButtonGroup.Items.Add;
  Result.Caption := ACaption;
  Result.Hint := Format('Hint of %s button.', [ACaption]);
  Result.ImageIndex := AImageIndex;
  Result.SetButtonStyle(AFamily, AClass, AAppearance);
end;

Per-Item Styling ​

Each button in the group can have its own style:

pascal
// Button 1 - Primary Outline
AddStyledButtonToButtonGroup(FStyledButtonGroup, 'Caption1', 0,
  BOOTSTRAP_FAMILY, btn_primary, BOOTSTRAP_OUTLINE);

// Button 2 - Secondary Outline
AddStyledButtonToButtonGroup(FStyledButtonGroup, 'Caption2', 5,
  BOOTSTRAP_FAMILY, btn_secondary, BOOTSTRAP_OUTLINE);

// Button 3 - Success Outline
AddStyledButtonToButtonGroup(FStyledButtonGroup, 'Caption3', 8,
  BOOTSTRAP_FAMILY, btn_success, BOOTSTRAP_OUTLINE);

// Button 4 - Danger Outline
AddStyledButtonToButtonGroup(FStyledButtonGroup, 'Caption4', 10,
  BOOTSTRAP_FAMILY, btn_danger, BOOTSTRAP_OUTLINE);

Button Options ​

Full Size Mode (gboFullSize) ​

Buttons fill the full width of the container:

pascal
ButtonGroup.ButtonOptions := ButtonGroup.ButtonOptions + [gboFullSize];

Group Style Mode (gboGroupStyle) ​

Standard TButtonGroup option that draws the buttons as a group (see the Embarcadero help); with gboFullSize off the width of each button is ButtonWidth:

pascal
ButtonGroup.ButtonOptions := ButtonGroup.ButtonOptions + [gboGroupStyle];
ButtonGroup.ButtonWidth := 120;

Show Captions (gboShowCaptions) ​

Display button captions:

pascal
ButtonGroup.ButtonOptions := ButtonGroup.ButtonOptions + [gboShowCaptions];

Notification Badges ​

The demo includes notification badges on button items:

Enable Badges ​

pascal
procedure TfmStyledButtonGroup.StyledButtonGroupBootstrapGetNotificationBadgeInfo(
  const AButtonItemIndex: Integer;
  var ABadgeContent: string;
  var ASize: TNotificationBadgeSize;
  var APosition: TNotificationBadgePosition;
  var AColor, AFontColor: TColor;
  var AFontStyle: TFontStyles);
begin
  if (AButtonItemIndex = 0) then
    ABadgeContent := IntToStr(FNotificationCount + 10)
  else if (AButtonItemIndex = 1) then
  begin
    AColor := clBlue;
    ABadgeContent := IntToStr(FNotificationCount + 20);
  end;
end;

Animated Badges ​

The demo uses a timer to update badge counts:

pascal
procedure TfmStyledButtonGroup.BadgeTimerTimer(Sender: TObject);
begin
  Inc(FNotificationCount);
  StyledButtonGroupBootstrap.Repaint;  // Force badge update
end;

Image and Caption Alignment ​

Caption Alignment ​

pascal
// Left-aligned captions
ButtonGroup.CaptionAlignment := taLeftJustify;

// Centered captions
ButtonGroup.CaptionAlignment := taCenter;

// Right-aligned captions
ButtonGroup.CaptionAlignment := taRightJustify;

Image Alignment ​

pascal
// Image on left
ButtonGroup.ImageAlignment := iaLeft;

// Image on right
ButtonGroup.ImageAlignment := iaRight;

// Image on top
ButtonGroup.ImageAlignment := iaTop;

// Image on bottom
ButtonGroup.ImageAlignment := iaBottom;

// Image centered (no caption)
ButtonGroup.ImageAlignment := iaCenter;

Interactive Controls ​

The demo includes controls to modify appearance:

ControlFunction
Width TrackbarAdjust button width (in gboGroupStyle mode)
Height TrackbarAdjust button height
Show CaptionToggle caption visibility
Full SizeToggle full-size mode
Show IconToggle icon visibility
Caption AlignmentChange caption alignment
Image AlignmentChange image position

Button Click Handling ​

Handle button clicks with the OnButtonClicked event:

pascal
procedure TfmStyledButtonGroup.ButtonGroupButtonClicked(
  Sender: TObject;
  Index: Integer);
begin
  if Sender is TButtonGroup then
  begin
    if TButtonGroup(Sender).Items[Index] is TGrpButtonItem then
      StyledShowMessage(TGrpButtonItem(TButtonGroup(Sender).Items[Index]).Caption);
  end;
end;

Design-Time Button Group ​

The demo also shows button groups created at design-time:

Classic Style ButtonGroup ​

  • Default VCL appearance
  • All standard features

Bootstrap Style ButtonGroup ​

  • Bootstrap styling
  • Notification badges
  • Custom colors per item

Key Features ​

1. Per-Item Styling ​

Each button can have different:

  • StyleFamily
  • StyleClass
  • StyleAppearance
  • Colors
  • Icons

2. Notification Badges ​

Display badges on items:

  • Numeric counts
  • Custom text
  • Custom colors
  • Custom positions

3. Flexible Layout ​

  • Vertical or horizontal
  • Full-size or fixed-width
  • Customizable spacing

4. Item Selection ​

pascal
// Get selected item
SelectedIndex := ButtonGroup.ItemIndex;

// Set selected item
ButtonGroup.ItemIndex := 2;

Creating ButtonGroup Programmatically ​

Complete example:

pascal
var
  BtnGroup: TStyledButtonGroup;
  Item: TStyledGrpButtonItem;
begin
  // Create button group
  BtnGroup := TStyledButtonGroup.Create(Self);
  BtnGroup.Parent := Self;
  BtnGroup.Align := alLeft;
  BtnGroup.Images := ImageList1;
  BtnGroup.ButtonOptions := [gboFullSize, gboShowCaptions];

  // Add styled items
  Item := BtnGroup.Items.Add as TStyledGrpButtonItem;
  Item.Caption := 'Home';
  Item.ImageIndex := 0;
  Item.SetButtonStyle(BOOTSTRAP_FAMILY, btn_primary, BOOTSTRAP_NORMAL);

  Item := BtnGroup.Items.Add as TStyledGrpButtonItem;
  Item.Caption := 'Settings';
  Item.ImageIndex := 1;
  Item.SetButtonStyle(BOOTSTRAP_FAMILY, btn_secondary, BOOTSTRAP_NORMAL);
end;

Key Differences from TButtonGroup ​

TStyledButtonGroup adds:

  1. Per-Item Styling: Each item can have unique Family/Class/Appearance
  2. Notification Badges: Built-in badge support
  3. Consistent Rendering: Same look across Windows versions
  4. Modern Appearance: Bootstrap, Angular, or custom styles
  5. Better DPI Support: Automatic scaling
  6. Extended Customization: More visual options

Technical Details ​

Source Location ​

Demos/source/StyledButtonGroupForm.pas

Supported Versions ​

All Delphi versions (XE6+)

Key Properties ​

PropertyDescription
ItemsCollection of button items
ItemIndexCurrently selected item index
ButtonOptionsLayout and display options
ButtonWidthButton width (gboGroupStyle mode)
ButtonHeightButton height
ImagesImageList for icons
CaptionAlignmentCaption text alignment
ImageAlignmentIcon position
StyleFamilyDefault style family for items
StyleClassDefault style class for items

Key Events ​

EventDescription
OnButtonClickedFires when item is clicked
OnGetNotificationBadgeInfoProvides badge information

See Also ​

Released under Apache License, Version 2.0.