TBtnFlat
Source: source/classes/btnflat.prg
Inherits from: TControl
TBtnFlat is a flat borderless button with a hover highlight effect. It draws its caption centered over a solid color background and reacts to mouse clicks via a code block action. The button can optionally display a border, and its text and pane colors are fully customizable.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cCaption | Character | Button caption text |
bAction | Block | Code block executed when the button is clicked |
nClrText | Numeric | Text color (RGB value, default CLR_WHITE) |
nClrPane | Numeric | Background pane color (RGB value, default CLR_BLUE) |
oFont | Object | Font object for the caption text |
lBorder | Logical | Show a border around the button |
lTransparent | Logical | Transparent background (no fill) |
lPressed | Logical | Whether the button is currently pressed |
nClrTextDis | Numeric | Text color when disabled |
nClrPaneDis | Numeric | Pane color when disabled |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, cPrompt, oWnd, oFont, bAction, bWhen, lUpdate, lBorder, nClrText, nClrPane, lCancel, lDefault ) | Create a new flat button |
ReDefine( nId, bAction, oWnd, ... ) | Redefine from a dialog resource |
Click() | Execute the button action (evaluates bWhen, then bAction) |
Paint() | Draw the button background and centered caption |
LButtonDown( nRow, nCol, nFlags ) | Handle mouse down with working state tracking |
LButtonUp( nRow, nCol ) | Handle mouse up and trigger click if within control |
DrawMultiLine( cText, oFont, nColor, nAlign ) | Draw multi-line caption text with alignment |
Example: Flat Button with Hover
#include "FiveWin.ch"
function Main()
local oWnd, oBtn
DEFINE WINDOW oWnd TITLE "TBtnFlat Demo" SIZE 400, 200
@ 40, 60 FLATBTN oBtn ;
PROMPT "&Click Me" ;
OF oWnd ;
SIZE 100, 30 ;
ACTION MsgInfo( "Flat button pressed!" ) ;
COLOR CLR_WHITE, CLR_BLUE
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TBtnFlat does not use the standard Windows button control painting; it draws the caption using GDI text functions with full alignment control.
- Set
lBorderto .T. to draw a colored border around the button usingnClrText. - When
lDefaultis .T., the button receives theBS_DEFPUSHBUTTONstyle and responds to the Enter key. - Use
lCancelto let the button respond to the Escape key. - The button automatically calculates its width from the caption text if the provided width is too small.