Table of Contents
- About the Author
- 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
Adding Pull-Down Menu Options
Each menu bar command opens a pull-down menu that consists of a series of options, separator bars, access keystrokes, and submenus. The Menu Editor's four arrow command buttons let you indent the pull-down menu commands from their matching menu bar commands to show which items go with which menu bar commands.
Now that you've added the menu bar, you can add the individual options to the pull-down menus. You didn't have to complete the menu bar before completing each pull-down menu. You could have added the File option to the menu bar and then completed the File option's pull-down menu before adding the View option to the menu bar. The order in which you add menu items doesn't matter at all. It is where you place them and how you indent them that determines the order in which the menu items appear.
The File pull-down menu will contain the following items:
- The New command
- The Open command with a shortcut access keystroke of Ctrl+O
- he Close command
- A separator bar
- The Exit command
After you add these submenu items, you can hook up the menu commands to Click() event procedures that you write, as explained in the next section.
Adding pull-down items requires that you follow the same steps you followed when you added the menu bar items in the previous section. The difference is that the Menu Editor options that the previous section ignored, such as the Shortcut option, become more important because you'll apply some of these options to the pull-down menu items. Table 17.1 explains the remaining Menu Editor properties.
Table 17.1. The Menu Editor's remaining properties.
|Checked||Indicates whether a menu item has a check mark next to it. Generally, you'll add check marks to menu options that perform on or off actions, such as a View menu that contains a Highlighted command. The check mark appears when you, at design time or through code, set the menu item's Checked property to True. The check mark goes away (indicating that the item is no longer active or selected) when you set the Checked property to False.|
|HelpContextID||This is a code that matches a help file description if and when you add help files to your application.|
|Index||If you create a menu control array rather than name individual menu items separately, this Index property specifies the menu item's subscript within the control array.|
|Shortcut||This is a drop-down list of Ctrl+keystroke access keys that you can add to any pull-down menu item.|
|Window List||Specifies whether the menu item applies to an advanced application's MDI (multiple-document interface) document. The menus that you create for this book don't require the use of MDI features.|
Perhaps the most important command keys on the Menu Editor when you add pull-down menu items are the four arrow command buttons. The left and right arrow command buttons indicate which items go with which menu bar option. In other words, if four items in the lower window are indented to the right and appear directly beneath the File menu bar item, those four indented items will appear on File's pull-down menu. The left arrow removes an indentation level and the right arrow adds an indentation level. The up- and down-arrow keys move menu items up and down the list of menu items, rearranging the order if you need to do so.
The arrow keys make a lot of sense when you see them used. Follow these steps to create the File pull-down menu's submenu:
- Move the lower window's highlight line to the &Edit menu bar item. Click the Insert command button. You always insert before an item, so to add items to the File menu, you must insert before the Edit menu bar item in the lower window.
- Click the right-arrow command button. Visual Basic adds four dots (similar to an ellipsis), showing that the newly inserted item will be indented under the File option.
- Move the focus to the caption prompt and type &New.
- Press Tab to move the focus to the name prompt and type mnuFileNew.
- Click Next and then Insert, and click the right-arrow command button to insert another item beneath the New item. Your Menu Editor should look like the one in Figure 17.6. Notice that the File menu bar option now has a pull-down menu; you know this because of the indentation of the New option right below &File.
Figure 17.6 The File pull-down menu is gaining additional options.
- Move the focus to the caption prompt and type &Open. Press Tab and enter the Name property value mnuFileOpen. Rather than add the next item, click the Shortcut drop-down list and select Ctrl+O from the list. When the user now displays the File pull-down menu, Ctrl+O will appear as the shortcut key next to the File | Open menu item.
- Click Next, Insert, and then the right-arrow command button to make room for the next item. Add the Exit caption with the Name property mnuFileExit. Click Next again and then Insert to insert another item beneath the Close item. You can now add a separator bar.
Separator bars help you break individual pull-down menus into separate sections. Although several options appear on most Windows applications' File pull-down menus, these options don't all perform the same kind of tasks. Some options relate to files, some relate to printing, and the Exit command always appears on the File menu as well. The separator bars help distinguish groups of different items from one another on the pull-down menus.
All separator bars have the same Caption property, which is nothing more than a hyphen (-). You must give every separator bar a different name. Usually, the name of the separator bars on the File menu are mnuFileBar1, mnuFileBar2, and so on. Some programmers prefer to name the first separator bar Sep1, the second Sep2, and so on, no matter which menu the separator bar appears on.
You must add the separator bars on an indented menu level so that they indent properly beneath their pull-down menus. Follow these steps to add the single separator bar for this lesson's File pull-down menu:
- Type - (a hyphen) for the Caption property and press Tab.
- Type mnuFileBar1 for the Name property.
There's one more item to add: the Exit item. You know enough to add the Exit option to the File menu. After adding Exit, your Menu Editor should look like the one shown in Figure 17.7.
Figure 17.7 The File menu is now complete.