TSplitter
Fonte: source/classes/splitter.prg
Inherits from: TControl
TSplitter provides a draggable divider bar that allows users to resize adjacent control panels at runtime. It is commonly used to create resizable split-pane layouts (e.g. a tree view on the left and an edit area on the right) where the user can drag the splitter to allocate more or less space to each pane.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
lVertical | Logical | Vertical splitter (left/right panes) vs horizontal (top/bottom) |
aPrevCtrols | Array | Controls on the previous side (left/top) to be resized |
aHindCtrols | Array | Controls on the hind side (right/bottom) to be resized |
nFirst | Numeric | Initial position of the splitter in pixels |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, lVert, aPrev, lAdjPrev, aHind, lAdjHind, bMargin1, bMargin2, oWnd, bChange ) | Create a new TSplitter control |
SetPosition( n ) | Set the splitter position programmatically |
AdjClient() | Adjust the parent window client area accounting for the splitter |
Example: Vertical Splitter Between Tree and Edit
#include "FiveWin.ch"
function Main()
local oWnd, oTree, oEdit, oSplit
DEFINE WINDOW oWnd TITLE "Splitter Demo" SIZE 700, 500
@ 0, 0 TREE oTree SIZE 200, 500 OF oWnd
oTree:AddNode( "Node 1" )
oTree:AddNode( "Node 2" )
@ 0, 210 GET oEdit VAR cVar MEMO SIZE 480, 500 OF oWnd
@ 0, 200 SPLITTER oSplit ;
VERTICAL ;
PREVIOUS oTree ;
HIND oEdit ;
SIZE 10, 500 OF oWnd
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TSplitter automatically tracks mouse movement and resizes the previous and hind controls as the user drags the splitter bar.
- The
lVertparameter determines orientation:.T.for vertical (left/right panes),.F.for horizontal (top/bottom panes). aPrevCtrolsandaHindCtrolsaccept either a single control object or an array of controls to be resized together.- The
bChangecode block is fired each time the user finishes dragging to a new position, allowing application code to respond to the layout change. - Use
AdjClient()to make the splitter participate in the window's client-area resize logic, ensuring it repositions correctly when the window is resized.