TTabControl
Source: source/classes/ttabctrl.prg
Inherits from: TControl
TTabControl wraps the standard Windows SysTabControl32 common control. It displays a row of selectable tabs, each with a prompt, and notifies the application when the user clicks a tab via an action code block. TTabControl is a lightweight tab control without built-in page management — it fires an action on selection change and leaves the page-switching logic to the application. For automatic page switching, see TTabs or TPages.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
aPrompts | Array | Array of character strings displayed as tab labels. |
bAction | Block | Code block evaluated when the user clicks a tab: { |nOption, oCtrl| ... }. |
nOption | Numeric | Index of the currently selected tab (1-based). |
nClrText | Numeric | Text color for tab labels (RGB value). |
nClrPane | Numeric | Background fill color (RGB value). |
hFont | Numeric (Handle) | Handle of the font used for tab label text. |
oFont | TFont | Font object used for tab label text. |
cMsg | Character | Message bar text displayed when the tab control receives focus. |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, aPrompts, bAction, oWnd, nClrT, nClrP, oFont, lPixel, lDesign, nW, nH, cMsg ) | Create a new tab control. aPrompts is an array of tab label strings. bAction is called on tab selection. |
ReDefine( nId, oWnd ) | Redefine from a dialog resource. Links to an existing SysTabControl32 by its control ID. |
Add( cPrompt ) | Add a new tab at the end with the given label text. |
DelItem( nItem ) | Remove the tab at position nItem (1-based). |
SetPrompts( aPrompts ) | Replace all tab labels with a new array of strings. |
SetOption( nOption ) | Programmatically select a tab by its index. |
End() | Destroy the control. |
Commands: @ ... TAB
@ nRow, nCol TAB oTab ;
ITEMS aItems ;
[ SIZE nW, nH ] ;
[ OF oDlg ] ;
[ ACTION bAction ] ;
[ ON CHANGE bChange ] ;
[ COLOR nClrText, nClrPane ]
Example: 3-Tab Control with Action
#include "FiveWin.ch"
function Main()
local oWnd, oTab
local aPrompts := { "General", "Details", "Settings" }
DEFINE WINDOW oWnd TITLE "TTabControl Demo" SIZE 500, 400
@ 10, 10 TAB oTab ITEMS aPrompts ;
SIZE 460, 50 OF oWnd ;
ACTION MsgInfo( "Selected tab: " + Str( oTab:nOption ) )
@ 80, 20 SAY "Content area for tab " + Str( oTab:nOption ) ;
OF oWnd SIZE 300, 20
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TTabControl inherits from TControl. All standard control methods are available.
- Unlike TTabs (which manages child controls through page switching), TTabControl only wraps the tab strip itself. The application must handle content changes in response to
bAction. - Use
nOptionto read the currently selected tab index at any time, orSetOption()to change it programmatically. - Tab labels are set via
aPromptsin the constructor orSetPrompts()at runtime. Individual tabs can be added or removed withAdd()andDelItem(). - For automatic page management with child controls that show/hide based on the selected tab, use TFolder instead.
- Tabs can be repositioned at design time using
Move(),SetSize(), andSetPos().