home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Chapter 6
Scroller

The ExpenseReporter application described in Chapter 1 uses two scrolling areas. With two picture boxes and a scroll bar, it builds a region that the user can scroll to display more information than would otherwise fit on the screen. Building a scrolling area is not a difficult task, but it requires many tedious steps. The Scroller add-in automates those steps to create scrolling areas easily and quickly.

The first section in this chapter, “Using Scroller,” explains how this add-in works from an application developer’s point of view. It tells how a developer can use Scroller to create scrolling areas quickly.

The “Key Techniques” section that follows briefly lists the most important Visual Basic programming techniques used by Scroller. The rest of the chapter describes these techniques in detail.

Using Scroller

When it is installed, Scroller adds a Scroller submenu in the development environment’s Add-Ins menu. This submenu contains two commands: Create Scrolling Area and About. Figure 6.1 shows the new Add-In menu commands.

The About command presents a standard about dialog giving Scroller version and copyright information as well as a little help.

If the developer selects one or more controls and then invokes the Create Scrolling Area menu command, Scroller creates a scrolling area to contain the controls. Scroller creates three new picture boxes and two scroll bars that work together to display the controls. Figure 6.2 shows schematically how these controls are arranged.

The controls the developer selected are placed inside a picture box with a template named scroll_area. It is important to remember that scroll_area is a template representing a picture box, not the picture box itself. By default, Visual Basic will give the control a less descriptive name like Picture1.


FIGURE 6.1  Scroller’s Add-In submenu and commands.

Scroller makes the scroll_area object large enough to hold all the selected controls. Its border style is set to vbTransparent so it will be invisible on the form.

The scroll_area object is contained within an object with a template named viewport. This object has visible borders. As the program moves scroll_area within viewport, viewport’s edges clip off the parts of scroll_area that should not be visible.

Beside viewport are the two scroll bars with templates hscroll and vscroll. They behave much as the scroll bars described in Chapter 1 do. When their values change, they move scroll_area within viewport accordingly.


FIGURE 6.2  Control arrangement produced by Scroller.

Finally, all of these controls are contained in a picture box with a template named package. This object keeps the others together. It also provides a reference for setting properties for the scroll bars.
While the Scroller add-in can do most of the work, the application developer must perform three tasks to make the scrolling area work properly. First, the controls created by Scroller use several subroutines defined in the module Scroller.BAS. The developer must add this module to the project.
Second, when the form is first loaded, the program should call the package control’s Resize event handler. This allows the scrolling to arrange itself so it will be ready for display.
Finally, the form’s Resize event handler can resize the scrolling area if desired. For example, the following code shows a form’s Resize event handler that makes the package control Picture3 occupy all of the form’s available space.
Private Sub Form_Resize()
    Picture3.Move 0, 0, ScaleWidth, ScaleHeight
End Sub

After it creates the scrolling area, Scroller presents a message reminding the developer to perform these tasks.

Key Techniques

Scroller performs a single, well-defined task so it does not need to present a dialog box to ask the user for extra information. This makes it slightly different from the PropertySetter and Aligner add-ins described in the last two chapters. Those add-ins use a single Add-Ins menu command to present a dialog. Scroller creates two commands within a submenu in the Add-Ins menu.

The following list briefly describes the key techniques demonstrated by Scroller. The sections in the rest of this chapter describe these techniques in greater detail.

•  Creating Add-In Submenus. Unlike the add-ins described previously, Scroller adds a submenu containing two commands to the Add-Ins menu. This section describes the ConnectAddIn and DisconnectAddIn commands that add and remove these menu items.
•  Creating the Scrolling Area. To create the scrolling area, Scroller must create new controls, and it must properly arrange controls within each other. This section tells how Scroller accomplishes these two tasks.
•  Arranging Scrolling Area Controls. The package control Scroller creates contains a Resize event handler that arranges the controls it contains. This section lists the subroutines used to arrange the controls and set parameters for the scroll bars.

Creating Add-In Submenus

Scroller works slightly differently than the add-ins described in previous chapters. PropertySetter and Aligner present dialogs that allow the developer to indicate what properties to set and how controls should be aligned. A command button on the dialog allows easy access to a simple help screen that explains briefly what the add-in does.

Scroller, on the other hand, does not need any additional information to perform its task. It takes the selected controls and builds a scrolling area for them without presenting a dialog to get extra information. Because there is no dialog, there is no obvious place to provide help.

To provide help, Scroller installs an About command in the Add-Ins menu. To avoid cluttering the menu too much, it creates a separate submenu to hold the Create Scrolling Area and About commands, as shown in Figure 6.3.

Scroller creates the submenu and the menu commands in its ConnectAddIn subroutine. It removes them in DisconnectAddIn. Because Scroller creates two menu commands, it uses two global MenuLine variables and two global event handler IDs.

The main class that contains the ConnectAddIn and DisconnectAddIn subroutines is named Scroller. It also contains an AfterClick event subroutine that responds to the About menu command. This AfterClick subroutine presents an about dialog giving version and copyright information. It is similar to previous about dialog code so it is not described here.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.