Visual Basic Reference

SetViewport Method Example

The example uses SetViewport method to automatically place the TextBox control with focus into the top left corner of the Viewport of container. To try the example, place an array of three or more TextBox controls onto a UserDocument object. Paste the code below into the General section. Press F5 to run the project, then run Internet Explorer (3.0 or later). In Internet Explorer, type the path and file name of the ActiveX document (UserDocument1.vbd) into the Address box (the file will be in the same directory as the Visual Basic executable). When the ActiveX document is displayed, type any distinctive text into the first TextBox control. Press TAB to move to the next control to see the effect of the SetViewPort method.

  Private Sub Text1_GotFocus(Index As Integer)
   UserDocument.SetViewport Text1(Index).Left, _
      Text1(Index).Top
End Sub

Private Sub UserDocument_Initialize()
   ' The container must be small enough for scrollbars 
   ' to appear. To assure this, set the MinHeight and 
   ' MinWidth properties to be larger than the 
   ' container. 
   UserDocument.MinHeight = 10000
   UserDocument.MinWidth = 10000
End Sub