TScrollPanelEx
Fonte: source/classes/scrollex.prg
Inherits from: TPanel
TScrollPanelEx is an enhanced scrollable panel that supports horizontal scrolling of child controls with keyboard, mouse wheel, scroll bar, and gesture (touch/pan) input. It tracks the leftmost and rightmost child controls to compute the scroll range and provides automatic scrollbar management. The panel is commonly used for toolbars, ribbon-style layouts, and overflow containers.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hStep | Numeric | Horizontal scroll step in pixels (default 20) |
nScrollRange | Numeric | Computed scroll range based on child control positions |
oCtrlLeft | Object | Leftmost child control (used for scroll boundary) |
oCtrlRight | Object | Rightmost child control |
nRightMargin | Numeric | Right margin for auto-resize |
nBottomMargin | Numeric | Bottom margin for auto-resize |
aPages | Array | Named page positions for GoToPage navigation |
lScrollDrag | Logical | Drag-to-scroll mode flag |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nBottom, nRight, oWnd, lNoBorder ) | Create a scrollable panel. Pass lNoBorder := .T. to omit the border |
Redefine( nId, oWnd, lNoBorder ) | Redefine from a dialog resource |
SetRange() | Scan child controls and set the scroll range |
ScrollBy( nPix ) | Scroll content horizontally by the given pixel offset |
GoLeft() / GoRight() | Scroll to the extreme left or right |
GoLeftPix( nPix ) / GoRightPix( nPix ) | Scroll by a specific pixel amount |
PageLeft() / PageRight() | Scroll by two step sizes (page-style) |
GoToPos( nPos ) | Scroll to an absolute scrollbar position |
GoToPage( cPage ) | Scroll to a named page (registered via SetPage) |
SetPage( cPage, nCol ) | Register a named page at a given column position |
ControlIntoView( oControl ) | Scroll to ensure a specific control is visible |
hScroll( nWParam, nLParam ) | Handle horizontal scroll bar messages |
MouseWheel( nKeys, nDelta, nXPos, nYPos ) | Handle mouse wheel for horizontal scrolling |
HandleGesture( nGesture, nLParam ) | Handle touch pan gestures (kinetic scrolling) |
Example: Smooth Scroll Panel with Child Controls
#include "FiveWin.ch"
function Main()
local oWnd, oPanel, oBtn
DEFINE WINDOW oWnd TITLE "TScrollPanelEx Demo" SIZE 600, 150
@ 20, 20 SCROLLPANEX oPanel SIZE 560, 60 OF oWnd
for n := 1 to 15
@ 10, ( n - 1 ) * 90 BUTTON "Btn " + Str( n ) ;
SIZE 80, 30 OF oPanel PIXEL
next
oPanel:SetRange()
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- Call
SetRange()after adding all child controls to compute the scroll boundaries and attach focus-tracking for auto-scroll into view. - Use
SetPage( cName, nCol )withGoToPage( cName )for named-section navigation. - Drag scrolling is enabled by holding the left mouse button and dragging horizontally on the panel background.
- Touch gestures (pan) are supported on devices with touch input via the
HandleGesturemethod (GID_PAN).