TScrollPanel
Fuente: source/classes/scrlpanl.prg
Inherits from: TPanel
TScrollPanel is a scrollable container panel with automatic vertical and horizontal scrollbars that track the extent of child controls. It supports mouse-wheel scrolling, click-and-drag scroll, touch panning via gesture handling, page-based navigation, and helper methods to bring any child control into view. Created by G.N. Rao.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
vStep | Numeric | Vertical scroll step in pixels (default 20) |
hStep | Numeric | Horizontal scroll step in pixels (default 20) |
nScrollRange | Numeric | Vertical scroll range calculated from child controls |
nHScrollRange | Numeric | Horizontal scroll range calculated from child controls |
aSays | Array | Array of static text rectangles scrolled with the panel |
aPages | Array | Array of { cPageName, nRow } bookmarks for page navigation |
lScrollDrag | Logical | Drag-to-scroll mode flag |
nRightMargin | Numeric | Right margin preserved when parent resizes |
nBottomMargin | Numeric | Bottom margin preserved when parent resizes |
oCtrlTop | Object | Topmost child control (for scroll range) |
oCtrlBot | Object | Bottommost child control (for scroll range) |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nBottom, nRight, oWnd, lNoBorder ) | Create a new TScrollPanel |
SetRange() | Scan child controls and set scroll range. Call after adding all controls. |
ScrollBy( nV, nH ) | Scroll the panel by nV pixels vertically and nH pixels horizontally |
GoTop() | Scroll to the top of the panel |
GoBottom() | Scroll to the bottom of the panel |
GoLeft() | Scroll to the left edge |
GoRight() | Scroll to the right edge |
GoUp( nPix ) | Scroll up by nPix pixels (default vStep) |
GoDown( nPix ) | Scroll down by nPix pixels (default vStep) |
ControlIntoView( oControl ) | Scroll the panel to ensure oControl is visible |
SetPage( cPage, nRow ) | Bookmark the current row with a page name |
GoToPage( cPage ) | Scroll to a previously bookmarked page |
AddText( nRow, nCol, nW, nH, cbText, oFont, nClrText ) | Add scrolling text that moves with the panel content |
Example: Scroll Panel with Controls
#include "FiveWin.ch"
function Main()
local oWnd, oPanel, oGet, oBtn, cText := ""
DEFINE WINDOW oWnd TITLE "Scroll Panel" SIZE 400, 300
oPanel := TScrollPanel():New( 10, 10, 290, 390, oWnd )
@ 10, 10 GET oGet VAR cText OF oPanel SIZE 200, 20 PIXEL
@ 40, 10 BUTTON oBtn PROMPT "Button" OF oPanel SIZE 100, 30 PIXEL ;
ACTION MsgInfo( "Clicked" )
// Add more controls below the visible area to test scrolling
@ 400, 10 SAY "This is far down" OF oPanel SIZE 200, 20 PIXEL
oPanel:SetRange() // Recalculate scroll range
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- Call
SetRange()after adding all child controls to calculate the scroll range and enable the scrollbars. - The panel creates both vertical and horizontal scrollbars automatically via
WS_VSCROLLandWS_HSCROLLstyles. - Drag-to-scroll is enabled by holding the left mouse button and dragging. Touch panning is supported via
HandleGesture()for WM_GESTURE messages. - Use
ControlIntoView()inbGotFocusblocks of child controls to automatically scroll the panel when tabbing through controls. AddText()creates scrolling text labels that move with the panel content, unlike standard SAY controls which stay fixed unless scrolled manually.- The
nRightMarginandnBottomMarginDATA members allow the panel to auto-resize when its parent window is resized.