![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
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 printers orientation. If the user changes the printers 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 reports appearance, the user can select the Print command from the File menu to send the report to the printer. Managing FilesExpenseReporter 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.
HelpExpenseReporters Help menu allows the user to view the help files table of contents, search for help topics, see help about the current screen, or see an about dialog giving the programs 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 TechniquesThe rest of this chapter and Chapter 2 explain how ExpenseReporter was programmed. The following sections of this chapter describe key parts of the codeonly those sections that are particularly interesting or confusingin 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.
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 AreasBy 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 bars 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 bars Min property to 0.
|
|
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.
|