TBtnClr / TPickerColor
Source: source/classes/tbtnclr.prg
TBtnClr inherits from: TControl. TPickerColor is a standalone helper class.
TBtnClr is a color-picker button control that displays a selected color swatch and optionally a drop-down arrow bitmap. Clicking the button triggers an action (typically showing the TPickerColor dialog). TPickerColor provides a themed color selection dialog with a grid of standard colors, a row of base/theme colors, and a "More Colors" option using the system ChooseColor dialog.
Key DATA Members (TBtnClr)
| DATA | Type | Description |
|---|---|---|
nColorSel | Numeric | Currently selected color (RGB) |
nTypeClr | Numeric | Swatch display mode: 1=large, 2=small |
bAction | Block | Code block executed on click |
lDrawBorder | Logical | Draw a custom border around the button |
nColorBorder | Numeric | Border color |
hBmpPop | Handle | Optional drop-down arrow bitmap |
cMsg | Character | Message bar prompt text |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, oWnd, nWidth, nHeight, cBtnPop, nColorSel, nTypeClr, bAction, bWhenAct, cToolTip, lDesign, lDrawBorder, nClrText, nClrPane, nColorBorder ) | Create a color button control |
SetColor( nClr ) | Change the current selected color |
Click() | Trigger the button action |
Paint() | Render the button with theme or classic style, color swatch, and drop-down bitmap |
LoadBmp( cBitmap ) | Load the popup arrow bitmap from file or resource |
TPickerColor
| Method | Description |
|---|---|
New( nColor, oControl, cTitle1, cTitle2, cTitle3 ) | Create the picker dialog with customizable section titles |
Dialog( nColor ) | Build the dialog with color grid, base colors, and More Colors button |
Activate() | Show the dialog modally; returns .T. if a color was chosen |
Free function ChooseColor( nInitClr ) opens the standard Windows color picker and returns the selected RGB color.
Example: Color Button
#include "FiveWin.ch"
function Main()
local oWnd, oBtnClr, nColor := CLR_RED
DEFINE WINDOW oWnd TITLE "Color Picker Demo" SIZE 300, 150
@ 30, 30 BTNBMP oBtnClr PROMPT "Color" ;
SIZE 40, 25 OF oWnd ;
ACTION ( nColor := ChooseColor( nColor ), ;
oBtnClr:SetColor( nColor ), ;
oBtnClr:Refresh() )
@ 80, 30 SAY "Selected color shown on button" OF oWnd SIZE 200, 20
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TBtnClr supports Windows themes via
C5_DrawThemeBackgroundwith hover and pressed states. - The color swatch is rendered as a filled rectangle inside the button using
nColorSel. nTypeClrcontrols swatch positioning: 1 fills the button face, 2 leaves room for the popup arrow.- TPickerColor displays a 6x10 grid of standard colors plus a row of 10 theme/base colors. The "More Colors" button invokes the system
ChooseColordialog.