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

DATATypeDescription
vStepNumericVertical scroll step in pixels (default 20)
hStepNumericHorizontal scroll step in pixels (default 20)
nScrollRangeNumericVertical scroll range calculated from child controls
nHScrollRangeNumericHorizontal scroll range calculated from child controls
aSaysArrayArray of static text rectangles scrolled with the panel
aPagesArrayArray of { cPageName, nRow } bookmarks for page navigation
lScrollDragLogicalDrag-to-scroll mode flag
nRightMarginNumericRight margin preserved when parent resizes
nBottomMarginNumericBottom margin preserved when parent resizes
oCtrlTopObjectTopmost child control (for scroll range)
oCtrlBotObjectBottommost child control (for scroll range)

Methods

MethodDescription
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

Ver También