VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 14

Managing Active Document Scrolling

Your Active Document has some control over how it's placed and displayed in the container. Most of this control has to do with the behavior it will exhibit when the user tries to scroll through it within the container. Remember, because another application (the container) is hosting your document, your document can't have full control over its own appearance and behavior. With regards to scrolling, you may specify:
  • Whether or not your object will have scrollbars and what type they will be (Scrollbars property).

  • How small the container has to shrink before your document will receive horizontal or vertical scrollbars (MinHeight and MinWidth properties).

  • How far the scrollbar's "elevator box" will travel when the user clicks a scroll button (HScrollSmallChange and VScrollSmallChange properties).

  • How to behave whenever the user scrolls your document (Scroll event procedure).

  • How frequently to call the Scroll event (ContinuousScroll property).

Each of the above features is discussed in the following sections.

  1. The Scrollbars Property and MinHeight and MinWidth Properties
  2. The HScrollSmallChange and VScrollSmallChange Properties
  3. The Scroll Event Procedure and the ContinuousScroll Property

The Scrollbars Property and MinHeight and MinWidth Properties

You can use the Scrollbars property to determine whether the Active Document will appear in its container with horizontal scrollbars, vertical scrollbars, both types of scrollbars, or no scrollbars. Simply set the UserDocument's Scrollbars property to one of the four settings:

  • vbSBNone (0)

  • vbHorizontal (1)

  • vbVertical (2)

  • vbBoth (3)

Even if you set the Scrollbars property to display Scrollbars, your Active Document might not always show them. This is because the Active Document container's height (ViewPortHeight) or width (ViewPortWidth) must shrink below the values specified in the MinHeight or MinWidth property respectively. The respective Height and Width properties of the UserDocument determine the default values of the MinHeight and MinWidth properties. If ViewPortHeight is greater than MinHeight, no vertical scrollbar will appear regardless of the Scrollbars setting. If ViewPortWidth is greater than MinWidth, no horizontal scrollbar will appear regardless of the Scrollbars setting.

If you always want scrollbars to appear around your document application, simply set MinHeight and MinWidth to arbitrarily large values (equal to or greater than Screen.Height and Screen.Width). Your container will always be smaller than these specified sizes, and scrollbars will, therefore, always appear.

The HScrollSmallChange and VScrollSmallChange Properties

These properties control the distance that the scrollbar will move when the user clicks one of the "thumb screws" (the arrow buttons) at either end of the scrollbar. Units of measure are in twips, and the minimum value for these properties is 15 twips (slightly over 1/100th of an inch).

The Scroll Event Procedure and the ContinuousScroll Property

The UserDocument's Scroll event fires whenever the user makes a change on the Scrollbar. In Listing 14.6, the document's background color whimsically changes every time there is a Scroll event so you can see how often the event fires.


Private Sub UserDocument_Scroll()
'Whenever the user moves the scroll bar,
'we flash a different background color
BackColor = _
RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub

You can control how often the Scroll event fires by setting the ContinuousScroll property. The settings of this Boolean property have the following significance:

  • When ContinuousScroll is False, the Scroll event will not fire while the user is dragging the Scroll box. The event will only fire when the user releases the Scroll box.

  • When ContinuousScroll is True, the Scroll event will fire continuously as the user drags the Scroll box.

The setting of ContinuousScroll has no effect one way or another on the Scroll event if the user is clicking the scrollbar arrows or the shaft of the scrollbar. In these cases, the Scroll event fires once for every click.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved