Skip to content

TStyledButton - Technical Reference

Overview

TStyledButton is a windowed button control (TWinControl) that provides styled rendering with full keyboard focus support. It's a direct replacement for the standard VCL TButton with enhanced styling capabilities.

Class Hierarchy

TWinControl
  └─ TCustomStyledButton
      └─ TStyledButton

Unit

pascal
Vcl.StyledButton

Description

TStyledButton is a windowed control that provides all the functionality of TStyledGraphicButton plus focus management, tab-stop support, and keyboard interaction. It's designed as a drop-in replacement for TButton while offering extensive styling options not available in standard VCL buttons.

Like TStyledGraphicButton, rendering is handled by an internal TStyledButtonRender instance for consistency across the component library.

Key Features

  • Full focus support: TabStop, keyboard navigation, accelerator keys
  • Five button states: Normal, Pressed, Selected, Hot (hover), Disabled
  • Multiple style families: Classic, Bootstrap, Angular-Light, Angular-Dark, Basic-Color, SVG-Color
  • Custom shapes: Rectangle, RoundedRect, Rounded (full-round), Ellipse
  • Button modes: Normal, Default, Cancel, Split Button, Command Link
  • Image support: ImageList with state-specific images
  • Notification badge: Optional badge overlay
  • Auto-click: Automatic click after delay (for countdown dialogs)
  • 100% TButton compatible: Drop-in replacement with enhanced features

Main Properties

Styling Properties

PropertyTypeDescription
StyleFamilyTStyledButtonFamilyStyle family (Classic, Bootstrap, Angular-Light, Angular-Dark, Basic-Color, SVG-Color)
StyleClassTStyledButtonClassPredefined style class within the family
StyleAppearanceTStyledButtonAppearanceVisual variant (Normal, Outline, Flat, Raised, etc.)
StyleDrawTypeTStyledButtonDrawTypeButton shape (btRect, btRoundRect, btRounded, btEllipse)
StyleRadiusIntegerCorner radius for btRoundRect (default: 6)
StyleRoundedCornersTRoundedCornersWhich corners to round

Button Behavior

PropertyTypeDescription
DefaultBooleanDefault button (activated by Enter key)
CancelBooleanCancel button (activated by Escape key)
ModalResultTModalResultModal result for forms (mrOk, mrCancel, etc.)
StyleTButtonStyleButton style (bsButton, bsSplitButton, bsCommandLink)
DownBooleanButton pressed state (for toggle buttons)
GroupIndexIntegerButton group for radio-button behavior
AllowAllUpBooleanAllow all buttons in group to be unpressed

Focus and Keyboard

PropertyTypeDescription
TabStopBooleanCan receive focus via Tab key (default: True)
TabOrderIntegerOrder in tab sequence
ElevationRequiredBooleanShow administrator shield icon

Appearance Properties

PropertyTypeDescription
CaptionTCaptionButton text
CaptionAlignmentTAlignmentCaption alignment (taLeftJustify, taCenter, taRightJustify)
ShowCaptionBooleanShow/hide caption (default: True)
CommandLinkHintStringHint text for command link style
WordWrapBooleanEnable text word-wrapping
FlatBooleanFlat button appearance

Image Properties

PropertyTypeDescription
ImagesTCustomImageListImageList for button images
ImageIndexTImageIndexDefault image index
ImageNameTImageNameImage name (Delphi 10.4+)
ImageAlignmentTImageAlignmentImage position (iaLeft, iaRight, iaTop, iaBottom, iaCenter)
ImageMarginsTImageMarginsMargins around the image
HotImageIndexTImageIndexImage when mouse hovers
PressedImageIndexTImageIndexImage when button is pressed
SelectedImageIndexTImageIndexImage when button is selected
DisabledImageIndexTImageIndexImage when button is disabled
StylusHotImageIndexTImageIndexImage for stylus/touch hover

Split Button

PropertyTypeDescription
DropDownMenuTPopupMenuPopup menu for split button

Auto-Click Feature

PropertyTypeDescription
AutoClickBooleanEnable automatic click after delay
AutoClickDelayIntegerDelay in milliseconds before auto-click (default: 5000)

Notification Badge

PropertyTypeDescription
NotificationBadgeTNotificationBadgeAttributesBadge configuration

Compatibility

PropertyTypeDescription
AsVCLComponentBooleanSwitch to VCL-style rendering
KindTBitBtnKindButton kind (bkOK, bkCancel, bkYes, bkNo, etc.) for TBitBtn compatibility

Main Methods

RegisterDefaultRenderingStyle (Class Method)

Sets the default rendering style for all TStyledButton instances.

pascal
class procedure RegisterDefaultRenderingStyle(
  const ADrawType: TStyledButtonDrawType;
  const AFamily: TStyledButtonFamily = DEFAULT_CLASSIC_FAMILY;
  const AClass: TStyledButtonClass = DEFAULT_WINDOWS_CLASS;
  const AAppearance: TStyledButtonAppearance = DEFAULT_APPEARANCE;
  const AStyleRadius: Integer = DEFAULT_RADIUS); virtual;

Click

Programmatically clicks the button.

pascal
procedure Click; override;

Events

EventDescription
OnClickTriggered when button is clicked
OnEnterButton receives focus
OnExitButton loses focus
OnKeyDownKey pressed while button has focus
OnKeyUpKey released while button has focus
OnKeyPressCharacter key pressed
OnMouseEnterMouse enters button area
OnMouseLeaveMouse leaves button area
OnDropDownClickSplit button dropdown clicked (before menu shown)

Usage Examples

Basic Button (TButton Replacement)

pascal
var
  Btn: TStyledButton;
begin
  Btn := TStyledButton.CreateStyled(Self,
    BOOTSTRAP_FAMILY,
    btn_primary,
    BOOTSTRAP_NORMAL);
  Btn.Parent := Self;
  Btn.Caption := 'OK';
  Btn.ModalResult := mrOk;
  Btn.Default := True;  // Activated by Enter key
  Btn.OnClick := OKButtonClick;
end;

Split Button with Menu

pascal
Btn := TStyledButton.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_success,
  BOOTSTRAP_NORMAL);
Btn.Parent := Self;
Btn.Caption := 'Save';
Btn.Style := bsSplitButton;
Btn.DropDownMenu := SaveOptionsMenu;
Btn.OnClick := SaveClick;  // Main button click
pascal
Btn := TStyledButton.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_primary,
  BOOTSTRAP_NORMAL);
Btn.Parent := Self;
Btn.Caption := 'Continue';
Btn.CommandLinkHint := 'Proceed to the next step';
Btn.Style := bsCommandLink;
Btn.ImageIndex := 0;
Btn.ImageAlignment := iaLeft;

Button with Auto-Click

pascal
Btn := TStyledButton.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_primary,
  BOOTSTRAP_NORMAL);
Btn.Parent := Self;
Btn.Caption := 'Close (5)';
Btn.ModalResult := mrOk;
Btn.AutoClick := True;
Btn.AutoClickDelay := 5000;  // 5 seconds
// Update caption in timer to show countdown

Default Button Styling by ModalResult

pascal
// Buttons automatically style based on ModalResult
BtnOK := TStyledButton.Create(Self);
BtnOK.ModalResult := mrOk;  // Will use Success/Primary colors

BtnCancel := TStyledButton.Create(Self);
BtnCancel.ModalResult := mrCancel;  // Will use Warning colors

BtnNo := TStyledButton.Create(Self);
BtnNo.ModalResult := mrNo;  // Will use Danger colors

Toggle Button

pascal
BtnBold := TStyledButton.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_secondary,
  BOOTSTRAP_NORMAL);
BtnBold.Caption := 'B';
BtnBold.GroupIndex := 1;
BtnBold.AllowAllUp := True;
BtnBold.Down := False;
// Check Down property to determine state

Elevation Required (UAC Shield)

pascal
Btn := TStyledButton.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_primary,
  BOOTSTRAP_NORMAL);
Btn.Caption := 'Settings';
Btn.ElevationRequired := True;  // Shows Windows UAC shield icon

Setting Default Styles Globally

pascal
// In project DPR file, after Application.Initialize
uses
  Vcl.StyledButton, Vcl.ButtonStylesAttributes;

begin
  Application.Initialize;

  // All TStyledButton instances will use these defaults
  TStyledButton.RegisterDefaultRenderingStyle(
    btRounded,
    BOOTSTRAP_FAMILY,
    btn_primary,
    BOOTSTRAP_NORMAL
  );

  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

Replacing Standard TButton

Method 1: Direct Replacement

pascal
// Old code:
// var
//   Button1: TButton;

// New code:
var
  Button1: TStyledButton;

// All TButton properties and events are compatible!

Method 2: Using Interposer Unit

Add to project:

pascal
uses
  Vcl.StyledComponentsHooks;  // Automatically replaces TButton with TStyledButton

Important Notes

  • Focus Support: Unlike TStyledGraphicButton, this control can receive focus
  • Keyboard Accelerators: Supports Alt+Key accelerators (underlined characters in caption)
  • Default/Cancel: Can be designated as form's default or cancel button
  • ModalResult: Automatically closes parent dialog with specified result
  • TabStop: Participates in tab order navigation
  • DPI Aware: Automatically scales with DPI changes
  • Thread-Safe: Can be safely created and manipulated from UI thread only

See Also

Released under Apache License, Version 2.0.