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


The user can select the Print Setup command from the File menu to select a printer and specify printer properties. For instance, most printers can print in portrait (normal) or landscape (sideways) orientation. The Print Setup command allows the user to change the printer’s orientation. If the user changes the printer’s orientation, the change is immediately reflected on the print preview screen. Figure 1.4 shows a preview of the same expense report shown in Figure 1.3 but in landscape orientation.

Once satisfied with the expense report’s appearance, the user can select the Print command from the File menu to send the report to the printer.

Managing Files

ExpenseReporter keeps track of the four files it has most recently accessed. It presents a list of those files near the bottom of its File menu. When the user opens an existing file or saves a new file to disk, this recent file list is updated. The user can select one of the recent file list entries to reload the corresponding file quickly.


FIGURE 1.2  ExpenseReporter’s print preview screen.


FIGURE 1.3  Print preview screen at small scale.

Help

ExpenseReporter’s Help menu allows the user to view the help file’s table of contents, search for help topics, see help about the current screen, or see an about dialog giving the program’s copyright and version information.

The user can also place the cursor in any data field and press the F1 key to see context-sensitive help about that field. The help file supplied with ExpenseReporter is fairly small. Most production applications have far more extensive help systems.

Key Techniques

The rest of this chapter and Chapter 2 explain how ExpenseReporter was programmed. The following sections of this chapter describe key parts of the code—only those sections that are particularly interesting or confusing—in detail. Control placement and source code that is straightforward are not described here. The complete source code for the application is on the accompanying compact disk. See the section “Using the Compact Disk” in the Introduction for instructions on loading the source code from the disk.


FIGURE 1.4  Print preview screen at small scale with landscape printer orientation.

The following list introduces the key techniques described in the rest of this chapter. Many of the topics are closely related. For example, file names play important roles in saving files and in recent file lists. You may need to read several sections to see how all the pieces fit together.

•  Creating Scrolling Areas. A scrolling area allows a program to display more data than will fit within the available space. This section explains how ExpenseReporter manages its scrolling region.
•  Arranging Controls. Whenever the user resizes the expense report form, ExpenseReporter rearranges its controls to take full advantage of the form’s new size. This section describes the Resize event handler that performs this rearrangement.
•  Creating Controls Dynamically. ExpenseReporter adds new expense rows as they are needed so the user always has a fresh row for entering data. This section tells how ExpenseReporter manages these controls.
•  Enhancing Field Navigation. When the input cursor lies within a Date, Location, or Amount field, the user can use the up and down arrow keys to move to the previous or next row. This section explains how ExpenseReporter provides this navigation feature.
•  Selecting a Document Interface. Single and multiple document interfaces (SDIs and MDIs) both have strengths and weaknesses. This section lists some of the trade-offs and tells which one is better under different circumstances.
•  Managing SDI Documents. A document management strategy ensures that documents modified by the user are properly saved. This section explains ExpenseReporter’s document management strategy.
•  Loading and Saving Files. Most applications load and save data. This section tells how ExpenseReporter loads and saves its data in files.
•  Designing Menus. By using a standardized menu structure, an application can make it easier for users to learn its user interface. This section describes menus that are common to many Windows applications.
•  Providing Recent File Lists. Providing a recent file list is simple but impressive. This section explains how ExpenseReporter’s recent file list works.

Creating Scrolling Areas

By using a scrolling area, an application can allow the user to view more information than will fit on the screen at one time. Visual Basic does not provide a simple scrolling area control, but with a little work you can build a scrolling area using the tools Visual Basic does provide.

The idea is to place controls within a picture box next to vertical and horizontal scroll bars. When the user adjusts the scroll bars, the program changes the Left and Top properties of the controls to make them move within the picture box. Visual Basic automatically clips off controls that lie beyond the edges of the picture box.

It is even easier to move the inner controls if they are all placed inside a picture box within the outer picture box. Then only the inner picture box needs to be moved; all of the controls it contains will move with it.

In ExpenseReporter the outer picture box is named Viewport. It acts as a viewport into a large piece of scrolling data.

The inner picture box, named ScrollArea, contains the expense row controls for the Date, Location, Category, Description, and Amount fields.

Figure 1.5 shows the Viewport and ScrollArea controls schematically. The shaded portions of Scroll-Area are beyond the edges of Viewport so they are not visible.

To move the ScrollArea up within the Viewport, the program decreases the value of ScrollArea.Top. This moves the top of ScrollArea upward, and the controls within it come along for the ride. Similarly, when the program increases ScrollArea.Top, ScrollArea moves down within the Viewport.

To give the user control over the scrolling process, ExpenseReporter adds a vertical scroll bar next to Viewport. The program adjusts ScrollArea.Top in the scroll bar’s Change and Scroll event handlers, as shown in the following code.

Private Sub ScrollBar_Change()
    ScrollArea.Top = -ScrollBar.Value
End Sub

Private Sub ScrollBar_Scroll()
    ScrollArea.Top = -ScrollBar.Value
End Sub

A scroll bar allows the user to select values that lie between those specified by its Min and Max properties. By default, these have the values 0 and 32,767. ExpenseReporter resets these properties so they control the ScrollArea properly.

When ScrollArea.Top is zero, the top of ScrollArea control lies at the top of Viewport. Increasing ScrollArea.Top moves ScrollArea down and exposes empty space at the top of the Viewport. To prevent the scroll bar from setting ScrollArea.Top to a value greater than zero and displaying this empty space, ExpenseReporter sets the scroll bar’s Min property to 0.


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.