Recent

Author Topic: BS PanelTrans - transforms panel to button, groupbox, checkbox, and radiobutton  (Read 522 times)

Xenno

  • New Member
  • *
  • Posts: 12
Hello,

I'm pleased to share a helper unit designed to transform a TPanel into a functional component that mimics a button, groupbox, checkbox, or radiobutton.

I created this primarily to enable customized styling, especially for color and font, beyond the standard controls. The resulting "fake" button supports TAction, Default and Cancel properties.

You can explore a full demonstration in the attached demo. I only test it in Windows. Please, inform if it works in other environment.

I welcome your comments and suggestions.


Cheers,


Lazarus 4.0, Windows 10

Handoko

  • Hero Member
  • *****
  • Posts: 5485
  • My goal: build my own game engine using Lazarus
Nice!
It works on Linux too.

Thank you for sharing it.

Xenno

  • New Member
  • *
  • Posts: 12
Nice!
It works on Linux too.

Thank you for sharing it.

Terima kasih kembali, Mas Handoko. The screenshot means a lot.
Lazarus 4.0, Windows 10

Xenno

  • New Member
  • *
  • Posts: 12
Introducing BS PanelTrans (v1.1): A TPanel Transformation Unit for Custom UI
« Reply #3 on: October 16, 2025, 08:43:32 pm »
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: TBSPanelTrans

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.

PropertyDescription
CaptionThe text displayed on the control.
Enabled, VisibleThe control's operational and visibility state.
Font, ParentFontFont property and the state to use the parent's font.
ParentColorState to use the parent's color.
Hint, ShowHintThe control's hint text and whether to display it.

Transforming to a Button: TBSPanelAsButton

This 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 Selectors

1. Group Box: TBSPanelAsGroupBox

This 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: 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

3. Radio Button: TBSPanelAsRadioButton

This 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 Code

The 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,
Lazarus 4.0, Windows 10

 

TinyPortal © 2005-2018