Skip to content

TStyledPanel - Technical Reference

Overview

TStyledPanel is a styled container control based on TCustomPanel that provides styled background rendering with full support for StyleFamily, StyleClass, and StyleAppearance properties. Available from version 3.9.1.

Class Hierarchy

TWinControl
  └─ TCustomPanel
      └─ TStyledPanel

Unit

pascal
Vcl.StyledPanel

Description

TStyledPanel extends TCustomPanel with modern styling capabilities similar to styled buttons. It provides styled background rendering with customizable shapes, colors, and borders while maintaining full compatibility with standard TPanel/TCustomPanel properties and behavior.

Unlike styled buttons that use TStyledButtonRender, TStyledPanel directly uses TStyledButtonAttributes for its Normal and Disabled states, providing a lightweight implementation optimized for container controls.

Development Note: This component was developed using Vibe Coding technique with Claude Code.

Key Features

  • Container control: Full TWinControl functionality with child control support
  • Two panel states: Normal and Disabled
  • Multiple style families: Classic, Bootstrap, Angular-Light, Angular-Dark, Basic-Color, SVG-Color
  • Custom shapes: Rectangle, RoundedRect, Rounded (full-round), Ellipse
  • Caption rendering: Customizable caption alignment and margins
  • VCL compatibility: Can switch between styled and VCL rendering
  • GDI+ rendering: Smooth antialiased rendering independent of VCL Styles
  • Standard panel features: Bevel, Border, Alignment, Docking support

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.)
StyleDrawTypeTStyledButtonDrawTypePanel shape (btRect, btRoundRect, btRounded, btEllipse)
StyleRadiusIntegerCorner radius for btRoundRect (default: 6)
StyleRoundedCornersTRoundedCornersWhich corners to round ([rcTopLeft, rcTopRight, rcBottomLeft, rcBottomRight])

Caption Properties

PropertyTypeDescription
CaptionTCaptionPanel caption text
CaptionAlignmentTAlignmentCaption horizontal alignment (taLeftJustify, taCenter, taRightJustify) - default: taCenter
CaptionMarginIntegerMargin around caption text (default: 4)
ShowCaptionBooleanShow/hide caption (inherited from TCustomPanel)
VerticalAlignmentTVerticalAlignmentCaption vertical alignment (taAlignTop, taAlignBottom, taVerticalCenter)

Standard Panel Properties

PropertyTypeDescription
AlignTAlignPanel alignment in parent
AlignmentTAlignmentContent alignment (deprecated, use CaptionAlignment)
BevelEdgesTBevelEdgesWhich edges have bevels
BevelInnerTBevelCutInner bevel style
BevelOuterTBevelCutOuter bevel style
BevelKindTBevelKindBevel kind (bkNone, bkTile, bkSoft, bkFlat)
BevelWidthIntegerWidth of beveled edges
BorderWidthIntegerBorder width
BorderStyleTBorderStyleBorder style (bsNone, bsSingle)
PaddingTPaddingInternal padding (Delphi 10.4+)

Compatibility

PropertyTypeDescription
AsVCLComponentBooleanSwitch to VCL-style rendering (uses VCL Styles if active)
ParentBackgroundBooleanUse parent's background
ParentColorBooleanUse parent's color

Container Properties

PropertyTypeDescription
DockSiteBooleanCan act as docking site
UseDockManagerBooleanUse docking manager (default: True)
FullRepaintBooleanRepaint entire panel on resize

Main Methods

RegisterDefaultRenderingStyle (Class Method)

Sets the default rendering style for all TStyledPanel instances created afterwards.

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;

Example:

pascal
// Set all panels to Bootstrap Light with rounded corners
TStyledPanel.RegisterDefaultRenderingStyle(
  btRounded,
  BOOTSTRAP_FAMILY,
  btn_light,
  BOOTSTRAP_NORMAL
);

SetPanelStyle

Changes the panel style at runtime.

pascal
procedure SetPanelStyle(
  const AStyleFamily: TStyledButtonFamily;
  const AStyleClass: TStyledButtonClass;
  const AStyleAppearance: TStyledButtonAppearance);

CreateStyled (Constructor)

Creates a panel with specific style settings.

pascal
constructor CreateStyled(
  AOwner: TComponent;
  const AFamily: TStyledButtonFamily;
  const AClass: TStyledButtonClass;
  const AAppearance: TStyledButtonAppearance);

Events

TStyledPanel supports all standard TCustomPanel events:

EventDescription
OnClickPanel clicked
OnDblClickPanel double-clicked
OnMouseDownMouse button pressed
OnMouseUpMouse button released
OnMouseMoveMouse moves over panel
OnMouseEnterMouse enters panel area
OnMouseLeaveMouse leaves panel area
OnResizePanel resized
OnDockDropControl docked onto panel
OnDockOverControl dragged over panel
OnEnterPanel receives focus
OnExitPanel loses focus

Usage Examples

Basic Styled Panel

pascal
var
  Panel: TStyledPanel;
begin
  Panel := TStyledPanel.CreateStyled(Self,
    BOOTSTRAP_FAMILY,
    btn_primary,
    BOOTSTRAP_NORMAL);
  Panel.Parent := Self;
  Panel.Align := alTop;
  Panel.Height := 60;
  Panel.Caption := 'Header Panel';
  Panel.StyleDrawType := btRoundRect;
  Panel.StyleRadius := 8;
end;

Panel as Card Container

pascal
Panel := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_light,
  BOOTSTRAP_NORMAL);
Panel.Parent := Self;
Panel.Align := alClient;
Panel.Caption := '';  // No caption
Panel.StyleDrawType := btRoundRect;
Panel.StyleRadius := 12;
Panel.BevelOuter := bvNone;
Panel.Padding.SetBounds(16, 16, 16, 16);  // 16px padding on all sides

// Add controls inside
var Lbl := TLabel.Create(Panel);
Lbl.Parent := Panel;
Lbl.Caption := 'Card Content';
Lbl.Align := alTop;

Info/Warning/Error Panels

pascal
// Info Panel
PanelInfo := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_info,
  BOOTSTRAP_NORMAL);
PanelInfo.Parent := Self;
PanelInfo.Caption := 'Information';
PanelInfo.StyleDrawType := btRoundRect;

// Warning Panel
PanelWarning := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_warning,
  BOOTSTRAP_NORMAL);
PanelWarning.Parent := Self;
PanelWarning.Caption := 'Warning';
PanelWarning.StyleDrawType := btRoundRect;

// Error Panel
PanelError := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_danger,
  BOOTSTRAP_NORMAL);
PanelError.Parent := Self;
PanelError.Caption := 'Error';
PanelError.StyleDrawType := btRoundRect;

Panel with Custom Caption Alignment

pascal
Panel := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_dark,
  BOOTSTRAP_NORMAL);
Panel.Parent := Self;
Panel.Caption := 'Left-Aligned Header';
Panel.CaptionAlignment := taLeftJustify;
Panel.CaptionMargin := 12;  // Left margin
Panel.VerticalAlignment := taAlignTop;
Panel.Height := 40;

Rounded Card Panel

pascal
Panel := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_light,
  BOOTSTRAP_NORMAL);
Panel.Parent := Self;
Panel.Caption := '';
Panel.StyleDrawType := btRoundRect;
Panel.StyleRadius := 16;
Panel.BevelOuter := bvNone;

// Round specific corners
Panel.StyleRoundedCorners := [rcTopLeft, rcTopRight];  // Only top corners rounded

Switch Between Styled and VCL Rendering

pascal
Panel := TStyledPanel.CreateStyled(Self,
  BOOTSTRAP_FAMILY,
  btn_primary,
  BOOTSTRAP_NORMAL);
Panel.Parent := Self;
Panel.Caption := 'Switchable Panel';

// Toggle between styled and VCL rendering
if CheckBoxUseVCLStyle.Checked then
  Panel.AsVCLComponent := True  // Use VCL Styles
else
  Panel.AsVCLComponent := False; // Use styled rendering

Setting Default Styles Globally

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

begin
  Application.Initialize;

  // All TStyledPanel instances will use these defaults
  TStyledPanel.RegisterDefaultRenderingStyle(
    btRoundRect,
    BOOTSTRAP_FAMILY,
    btn_light,
    BOOTSTRAP_NORMAL,
    8  // Radius
  );

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

Creating Styled Panel at Runtime with Specific Style

pascal
Panel := TStyledPanel.CreateStyled(
  Self,
  ANGULAR_LIGHT_FAMILY,
  acl_primary,
  ANGULAR_RAISED
);
Panel.Parent := Self;
Panel.Align := alTop;
Panel.Caption := 'Angular Styled Header';
Panel.Height := 50;

Differences from TStyledButton

AspectTStyledPanelTStyledButton
Base ClassTCustomPanelTWinControl
RenderingUses TStyledButtonAttributes directlyUses TStyledButtonRender
States2 (Normal, Disabled)5 (Normal, Hot, Pressed, Selected, Disabled)
PurposeContainer for child controlsInteractive button
FocusCan receive focus as containerButton-specific focus behavior
LayoutPanel-specific (Alignment, Bevel)Button-specific (ImageAlignment)

Important Notes

  • Container Control: Can contain child controls (labels, buttons, etc.)
  • Two States Only: Normal and Disabled (no Hot, Pressed, or Selected states)
  • DPI Aware: Automatically scales with DPI changes
  • VCL Compatibility: Full compatibility with TPanel/TCustomPanel
  • GDI+ Required: Requires Windows XP SP2+ for antialiased rendering
  • Bevel Support: Works with BevelInner, BevelOuter, BevelKind properties
  • Docking Support: Full docking capabilities inherited from TCustomPanel

See Also

Released under Apache License, Version 2.0.