THorzScroll
Source: source/classes/hrzscrol.prg
Inherits from: TPanel
THorzScroll extends TPanel with a built-in horizontal scrollbar that scrolls a collection of child panels. It is designed for horizontally scrollable layouts such as dashboard card rows, toolbar panels, or image galleries where content exceeds the visible width.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
oHScroll | Object | TScrollBar object managing the horizontal scrollbar |
nHPos | Numeric | Current horizontal scroll position |
nMaxWidth | Numeric | Total content width; determines the scroll range |
aPanels | Array | Array of child TPanel objects managed by the container |
nBetween | Numeric | Spacing in pixels between consecutive panels (default 10) |
lBorder | Logical | Show a border around the container |
nClrBorder | Numeric | Border color (RGB value) |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nBottom, nRight, oWnd, nClrPane, lHScroll, lBorder, nClrBorder ) | Create a new horizontal scroll panel |
Redefine( nId, oWnd, nClrPane, lHScroll, lBorder, nClrBorder ) | Redefine from a dialog resource |
AddPanel( nWidth, nClrBack ) | Add a child panel to the scrollable area; returns the panel object |
RemovePanel( xParam ) | Remove a child panel by index or object reference |
HScroll( nCode ) | Handle scroll events (line left/right) |
UpdateScrollRange() | Recalculate the scrollbar range after adding/removing panels |
StartSmoothScroll( nNewPos ) | Begin smooth animated scrolling to a target position |
Example: Horizontal Scroll Panel
#include "FiveWin.ch"
function Main()
local oWnd, oHS, oP1, oP2, oP3
DEFINE WINDOW oWnd TITLE "THorzScroll Demo" SIZE 600, 200
@ 10, 10 PANEL oHS OF oWnd SIZE 560, 150
oP1 := oHS:AddPanel( 150, CLR_RED )
oP2 := oHS:AddPanel( 150, CLR_GREEN )
oP3 := oHS:AddPanel( 150, CLR_BLUE )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- THorzScroll internally creates a
TScrollBarvia::oHScrollwith bound code blocks for line, page, and thumb-track scrolling. - Use
AddPanel()to append child panels. Each panel is sized according tonWidthand automatically positioned withnBetweenspacing. UpdateScrollRange()recalculatesnMaxWidthfrom the total width of all child panels to set the scrollbar maximum.- The
MouseWheelmethod supports horizontal scrolling via the mouse wheel when the panel has focus.