Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
What the Common Dialog Box Does
The Common Dialog Box control is perhaps the most powerful control available because of its capability to become one of several common dialog boxes you've surely seen in Windows applications. In Hour 10, "List Boxes and Data Lists," you learned that the Combo Box control is multifaceted because the control acts like one of three kinds of combo boxes, depending on the Style property you set. The common dialog box goes far beyond the combo box's capability to take on different looks and purposes.
When you place a common dialog box on a form, you won't be able to resize it because the control, like the Timer control, will not appear on the form at runtime, at least not right away. Your runtime code will have to display the common dialog box, and the look of the common dialog box displayed depends on what your code needs at the time.
If you are going to work with a data file, you could display the File Open dialog box, shown in Figure 12.1.
Figure 12.1 Using the common File Open dialog box to request a filename and location.
The quick viewer is a Windows application that pops up when you right-click a filename. The quick viewer application displays the file in its native format without requiring you to own the original format's parent application (such as Lotus 1-2-3).
You've seen the File Open dialog box in many Windows applications. The dialog box works just as it does in Microsoft Word and other applications; the user can select a pathname or a filename, change the view by clicking one of the View buttons, open the file as read-only so no changes are made to the file, and even select another drive or computer to choose from by clicking the drop-down list box.
The Common Dialog Box control also presents a similar file-related dialog box, shown in Figure 12.2, that produces a File Save dialog box. The user will also be familiar with the File Save dialog box. Your application can control the type of files displayed (by setting an appropriate filename extension type value) and can respond to the user's selection.
Figure 12.2 The File Save dialog box is also familiar to Windows users.
Figure 12.3 shows another common dialog box that the Common Dialog Box control can generate. Your applications can display the Color dialog box any time you want the user to select a color for an application such as a drawing application. Windows supports several million colors, and the Color dialog box shows only a few at a time. However, the user can locate the exact color desired from the Color dialog box or define his or her own custom colors by clicking the dialog box's Define Custom Colors button.
Figure 12.3 The Color dialog box is used by the user to pick a color.
The Font dialog box, shown in Figure 12.4, is another common dialog box that the Common Dialog Box control can display for you. When your application works with text, you should give your user the chance to select a font name or style. Your application cannot always know in advance which fonts the user will have on his system. The Font dialog box will, however, give the user a chance to select font information from his own computer. Once selected, your application can use the user's selection values to generate the text in the selected font.
Figure 12.4 The Font dialog box shows font information from the user's system.
The Print dialog box, shown in Figure 12.5, displays a common printer dialog box that you can display before printing any information to the printer. The dialog box returns information the user selects about the pending print job. As with the other controls, the Print dialog box only returns information to your application; it's up to your application to look at all relevant return information and respond accordingly. Therefore, if the user elects to print six copies, your code that follows the display of the Print dialog box must print six copies of the printed output.
Figure 12.5 The Print dialog box lets the user select a printer for output.
The final dialog box that the Common Dialog Box control can display is a Help window, such as the one in Figure 12.6. The Help window is linked to a help file that you generate. Generating help files is not a trivial task, as you'll see in Hour 23, "Distributing Your Applications." Therefore, this lesson doesn't show you how to connect a help file to your application. However, the Common Dialog Box control's Help dialog box can produce the front-end dialog box your user interacts with when you learn more about providing help in Hour 23.
Figure 12.6 The Help dialog box lets the user request the help needed.
Adding the Common Dialog Box Control | Next Section

Account Sign In
View your cart