TBtnClr / TPickerColor

Fuente: 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)

DATATypeDescription
nColorSelNumericCurrently selected color (RGB)
nTypeClrNumericSwatch display mode: 1=large, 2=small
bActionBlockCode block executed on click
lDrawBorderLogicalDraw a custom border around the button
nColorBorderNumericBorder color
hBmpPopHandleOptional drop-down arrow bitmap
cMsgCharacterMessage bar prompt text

Methods

MethodDescription
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

MethodDescription
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

Ver También