BS PanelTrans is a helper unit is designed to overcome the styling limitations of standard VCL/LCL controls in Lazarus and Delphi applications. The core idea is to transform a simple TPanel into a functional UI element that behaves like a Button, Speed Button, BitBtn, Group Box, Check Box, or Radio Button.
The main intention behind this unit is to allow complete customization of color and font, which is often unavailable in standard controls. This makes it perfect for implementing custom color themes in your applications!
Note: The classes created by this unit must be freed manually, typically in the form's OnDestroy event.
This is the base class for all transformations and provides the core functionality. It utilizes a TPanel and a TLabel (which can be created internally if needed). You should not use this class directly in your application.
Initial property values are derived from the panel being transformed.
Property Description
Caption The text displayed on the control.
Enabled, Visible The control's operational and visibility state.
Font, ParentFont Font property and the state to use the parent's font.
ParentColor State to use the parent's color.
Hint, ShowHint The control's hint text and whether to display it.
Transparent The control's opacity. Default is true except for button and bitbtn.
Cursor Mouse cursor when it hovers.
This class transforms the panel into a regular button, speed button, or bitbtn. It internally manages a TShape, a TButton (for functionality), and a TTimer (for periodic state updates).
They fully support TAction, monitoring its properties via the timer and reflecting changes in the button's appearance.
Styling & Action Properties
Colors: Color, HoverColor, ClickColor, DownColor, and BorderColor.
Border: BorderOnHover (shows border only on hover, or always).
Display: ShowCaption and RoundCorners.
Behavior: Default (activated by Enter), Cancel (activated by ESC), and Down state.
Action/Result: Action (assigns a TCustomAction) and ModalResult. A TPopupMenu can be used to be displayed when this button clicked assigned to DropDownMenu.
Glyph/Image: Images (for TImageList support) and ImageIndex or Picture (for direct image assignment).
Display: ShowCaption (to hide/show the caption text) and RoundCorners (round corners or not).
Methods & Events
Invalidate: Refreshes the button's appearance.
PrcSetupColors: Assigns color values, useful for setting light or dark schemes.
Click: Programmatically simulates a button click.
Event: OnClick (TNotifyEvent) is provided or derived from panel.
1. Group Box: TBSPanelAsGroupBox
This class internally draws a distinctive border around the panel area.
Properties: BorderColor.
Method: Invalidate (refreshes the group box appearance).
Note: This class may not be strictly necessary for Delphi, depending on the VCL version's TGroupBox styling capabilities.
2. Check Box: TBSPanelAsCheckbox
This produces a check box control by internally creating and managing a TCheckBox component.
Property: Checked (Set or get the checked state).
Event: OnClick (TNotifyEvent) is provided or derived from panel.
3. Radio Button: TBSPanelAsRadioButton
This produces a radio button control by internally creating and managing a TRadioButton component.
Property: Checked (Set or get the state) and GroupId (to link radio buttons of the same parent).
Event: OnClick (TNotifyEvent) is provided or derived from panel.
The demo written in Lazarus contains the full helper unit, uBSPanelTrans. Please run the demo to see BS PanelTrans in action and learn more about its implementation.
The pictures below are screenshots of the demo showing how BS PanelTrans transforms panels, compared side-by-side with the standard controls.