Hello everyone,
I'm pleased to share
BS PanelTrans, now at
version 1.1!
This helper unit is designed to overcome the styling limitations of standard VCL/LCL controls in
Lazarus and
Delphi applications. (For those who saw the initial v1.0 post, this is the updated release!)
The core idea is to transform a simple
TPanel into a functional UI element that behaves like a
Group Box,
Check Box,
Radio Button, or a regular
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, usually in the form's
OnDestroy event.
The Ancestor Class: TBSPanelTransThis 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. |
Transforming to a Button: TBSPanelAsButtonThis class transforms the panel into a regular or speed button. It internally manages a
TShape, a
TButton (for functionality), and a
TTimer (for periodic state updates).
A key feature is its ability to be assigned a
TAction, with its properties being monitored and reflected in the button's appearance via the timer.
Styling & Action Properties- Colors: Color, HoverColor, ClickColor, DownColor, and BorderColor.
- Border: BorderOnHover (determines if the border is shown only on hover or always).
- Behavior: Default (activated by Enter), Cancel (activated by ESC), and Down state.
- Action/Result: Action (assigns a TCustomAction) and ModalResult.
- 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.
Transforming to Containers and Selectors1. Group Box: TBSPanelAsGroupBoxThis class internally creates a
TShape to draw the distinctive border around the panel area.
- Properties: BorderColor and RoundCorners.
- Method: Invalidate (refreshes the group box appearance).
2. Check Box: TBSPanelAsCheckboxThis produces a check box control by internally creating and managing a
TCheckBox component.
- Property: Checked (Set or get the checked state).
- Event: OnClick
3. Radio Button: TBSPanelAsRadioButtonThis produces a radio button control by internally creating and managing a
TRadioButton component.
- Property: Checked (Set or get the checked state).
- Event: OnClick
Explore the CodeThe attached demo contains the full helper unit,
uBSPanelTrans. Please run the demo to see
BS PanelTrans v1.1 in action and learn more about its implementation.
I hope this updated unit proves useful to the community! I would be grateful for any
comments, suggestions, critique, or bug report you might have.
Cheers,