The Active Document's
ViewPort is the screen area that the
container allocates for the display of the document.
-
The ViewPort Coordinate Properties
-
SetViewPort Method
The ViewPort Coordinate Properties
You can discover the size and coordinates of this area with the
ViewPortWidth, ViewPortHeight, ViewPortTop, and ViewPortLeft
properties. The meaning of each of these properties is
-
ViewPortWidth. The horizontal size (in twips) of
the area that the container is using to display your document.
-
ViewPortHeight.
The vertical size (in twips) of the
area that the container is using to display
your document.
-
ViewPortTop.
The vertical coordinate (y-coordinate)
of the point on your document at the top
of the ViewPort. As the user scrolls downward
through the container's ViewPort over
your document's surface, more and
more of the document disappears off the
top edge of the ViewPort and the value of
ViewPortTop grows. When the user
scrolls upward through the container over
your document's surface, more and
more of the document appears from the top
edge of the ViewPort and the value of
ViewPortTop decreases.
-
ViewPortLeft.
The horizontal coordinate (x-coordinate)
of the point on your document at the left
of the ViewPort. As the user scrolls to
the right through the container's
ViewPort over your document's surface,
more and more of the document disappears
off the left edge of the ViewPort and the
value of ViewPortLeft
grows. When the user scrolls to the
left through the container over your document's
surface, more and more of the document appears
from the left edge of the ViewPort and the
value of ViewPortLeft
decreases.
To illustrate the behavior of
ViewPortTop and ViewPortLeft,
you can put the code shown in Listing 14.7 into
the Scroll event
procedure so that you can print the value of
ViewPortLeft and
ViewPortTop on the surface of the document
whenever the user scrolls. You can see the results
in Figure 14.1 and Figure 14.2.
LISTING 14.7
DISPLAYING ViewPortTop AND ViewPortLeft IN THE
Scroll EVENT PROCEDURE
Private Sub UserDocument_Scroll()
'initialize a string for message
Dim msg As String
'Get ViewPortTop and ViewPortLeft
'into message
msg = "TOP: " & _
UserDocument.ViewportTop
msg = msg & " LEFT: " &
_
UserDocument.ViewportLeft
'Clear graphics output surface
'of document
UserDocument.Cls
'save current font size
Dim OldFontSize As Long
OldFontSize = Font.Size
'change font size to 48 pt.
Font.Size = 48
'calculate point to begin
'text output based on current
'position of ViewPort (calculated
'point will center text on screen)
UserDocument.CurrentX = _
((ViewportWidth - TextWidth(msg)) / 2) _
+ ViewportLeft
UserDocument.CurrentY = _
((ViewportHeight - TextHeight(msg)) / 2) _
+ ViewportTop
'Print out message
UserDocument.Print msg
'and restore font to previous size
Font.Size = OldFontSize
End Sub
In Figure 14.1, you've scrolled
all the way to the top and left of the document,
so ViewPortTop and
ViewPortLeft are both 0.

FIGURE 14.1 ViewPortTop
and ViewPortLeft
are both set at 0.
In Figure 14.2, you've scrolled
a bit down and to the right, so part of the
document has disappeared off the left and top
edges of the container. The values of
ViewPortTop and ViewPortLeft
in this figure represent the coordinates
of the top left-most point of our document that's
visible in the container.

FIGURE 14.2 ViewPortTop
and ViewPortLeft
have changed because you've scrolled
the document down and to the right.
SetViewPort
Method
You can use the
SetViewPort method to set the property
values of ViewPortTop and
ViewPortLeft. The effect of setting these
values is to position the point on your document
whose coordinates correspond to
ViewPortTop and ViewPortLeft
in the upper left corner of the container
window. You call the SetViewPort
method with two parameters whose values
correspond to the desired
ViewPortLeft and
ViewPortTop properties.
For instance, the code
SetViewPort
100, 0
positions the document so that
the first 100 twips (about 2/3 of an inch) are
cut off at the left edge of the container window
and the top of the document is flush with the
top of the container window.
If you want a particular control
on your UserDocument to
be in the upper-left corner of the container
window, use its Left and Top properties as the
arguments to the SetViewPort
method:
SetViewPort Text1.Left,
Text1.Top
Even though the SetViewPort method resets the position
of your document inside the ViewPort, it does not fire
the Scroll event.