Visual Basic Concepts
ActiveX Document Viewport
An ActiveX document cannot be viewed as a stand-alone application — it must be viewed in a container application. The area in the container application through which the document is visible is also known as the Viewport. The following figure illustrates the Viewport of Internet Explorer.
Naturally, the Viewport can be resized by the user, and the developer has no control over this. However, using the SetViewPort method, you can manipulate which part of an ActiveX document is shown in the Viewport. First, however, let's examine other Viewport features, as understanding them will make it easier to the SetViewPort method.
The ViewPortTop, ViewPortLeft, ViewPortHeight, and ViewPortWidth Properties
The ViewPortHeight, ViewPortWidth, ViewPortLeft, and ViewPortTop properties are read-only properties. They return the coordinates of the Viewport relative to the ActiveX document. The following figure shows Internet Explorer overlaying the ActiveX document. The Viewport properties are called out. Notice that in this case the ActiveX document is larger than the Viewport. In reality, when the Viewport is too small to show the entire document, scrollbars will appear. (The scrollbars, however, can be turned off by setting the ScrollBars property to False. Note that this is a read-only property, and must be set at design time).
The following figure shows the Viewport properties after the user has scrolled to see the other parts of the document; notice that only the ViewPortLeft and ViewPortTop properties have changed:
Finally the following figure shows the Viewport properties after the user has resized the Viewport. Notice that the ViewPortHeight and ViewPortWidth have now changed:
The MinHeight, MinWidth Properties
Because an ActiveX document is contained by another application, you will have no control over how much space the container application gives to your ActiveX document. However, you will be able to specify the minimum space your ActiveX document needs before scrollbars appear by setting the MinHeight and MinWidth properties.
When you design an ActiveX document, the Height and Width of the UserDocument designer become the default settings for the MinHeight and MinWidth properties. Also, the MinHeight and MinWidth properties are always set to the ScaleMode of the UserDocument.
In the following figure, the ActiveX document is smaller than the Viewport. In this case, the container has no scrollbars, and the "empty" part of the Viewport is filled with the BackColor of the ActiveX document. However, if the user resizes the container so that the Viewport is smaller than the ActiveX document, scrollbars will appear.
The MinHeight and MinWidth properties are settable. In other words, you can cause scrollbars to appear on the container by simply setting the MinHeight and MinWidth properties to be larger than the Viewport properties. For example, imagine an ActiveX document that allows the user to insert any image into an PictureBox control, and that the control resizes automatically to the size of the image. By setting the MinHeight and MinWidth properties to always be larger than the control, you can assure that scrollbars will always appear to let the user see the entire image:
Private Sub Picture1_Resize()
UserDocument.MinHeight = _
Picture1.Height + 100
UserDocument.MinWidth = _
Picture1.Width + 100
End Sub
Using the SetViewPort Method to Scroll
You can cause the Viewport to scroll to a specific coordinate by using the SetViewPort method. The method requires two arguments, the Top and Left arguments. For example, by setting these arguments to the Left and Top properties of a TextBox placed on the document, you can programmatically ensure that the TextBox with the focus always appears in the top left corner of the ActiveX document. This is illustrated:
The HScrollSmallChange and VScrollSmallChange Properties
The HScrollSmallChange and VScrollSmallChange properties function like the SmallChange property (of the HScolllBar and VScrollBar controls).
Note There is no "HScrollLargeChange" or "VScrollLargeChange" property because the Viewport handles this for you automatically. The "LargeChange" value is determined by the current height and width of the Viewport.