How To Programmatically Scroll a Visual FoxPro Form (190818)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q190818

SUMMARY

Unlike the grid control, which has a scroll method that can be called to programmatically scroll through the grid records, a form has no such method.

You must use the SetViewPort method to programmatically scroll a Visual FoxPro 6.0 form.

MORE INFORMATION

The following sample form programmatically scrolls using the Page Up and Page Down keys:
   Sample Code
   -----------
				
   PUBLIC oform
   oform=NewObject("ScrollForm")
   oform.show

   DEFINE CLASS ScrollForm AS form
      Top = 0
      Left = 0
      Height = 101
      Width = 168
      ScrollBars = 2
      Caption = "Use PgUp/PgDwn to Scroll Form"
      vertscrollpos = 0
      Name = "Form1"
      ADD OBJECT shape1 AS shape WITH ;
         Top = 12, ;
         Left = 12, ;
         Height = 421, ;
         Width = 553, ;
         Name = "Shape1"
      ADD OBJECT command1 AS commandbutton WITH ;
         Top = 24, ;
         Left = 36, ;
         Height = 27, ;
         Width = 84, ;
         Caption = "Close", ;
         Name = "Command1"
      PROCEDURE KeyPress
         LPARAMETERS nKeyCode, nShiftAltCtrl
         IF nKeyCode=3
            Thisform.vertscrollpos=Thisform.vertscrollpos+Thisform.height
            Thisform.SetViewPort(0,Thisform.vertscrollpos)
            Thisform.Refresh
         ENDIF
         IF nKeyCode=18
            Thisform.vertscrollpos=Thisform.vertscrollpos-thisform.height
            Thisform.SetViewPort(0,Thisform.vertscrollpos)
            Thisform.Refresh
         ENDIF
      ENDPROC
      PROCEDURE command1.Click
         thisform.release
      ENDPROC
   ENDDEFINE
				

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbcode kbhowto KB190818