Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Adding an Application's Menu Bar

An application's menu bar is one of the easiest parts of the menu system to add. This section walks you through the steps necessary to add a menu bar. Subsequent sections show you how to add pull-down menu options to each of the menu bar commands.

The Menu Editor makes adding a menu bar to any application simple. Create a new project so that you can practice creating a menu. The menu bar you create will contain the following options:

This tutorial could go into a lot of detail, explaining all the nuances of the Menu Editor. Luckily, you don't need all that preliminary detailed description. The Menu Editor is most easily mastered by jumping in and building a menu from scratch. You don't need a bunch of theory to use the Menu Editor.

Every option on a menu bar, as well as the menu options, submenus, and separator bars that appear when you display a pull-down menu, has properties just as the other controls do. The Menu Editor acts like a dialog box that helps you set menu property values. The Properties window is perfect for the other controls, but as you'll see, menus require a few extra property choices that the other controls don't need. That's why using the customized Menu Editor is simpler than modifying an application's menu through the Properties window.

Perform the following steps to add a menu bar to your new project:

  1. Press Ctrl+E to display the Menu Editor. Each menu bar command requires a caption (specified by the Caption property) and a name (specified by the Name property). The other Menu Editor items are optional. The additional Menu Editor properties, such as the Enabled property that determines whether the menu item is grayed out and unavailable for certain procedures, as well as a Visible property, which determines when the user can see the menu bar command, are not needed for every option. You'll rarely change these extra property values from their default values for menu bar commands.
  2. At the Caption prompt, type &File. The ampersand, as with the other controls' Caption properties, indicates an accelerator keystroke of Alt+F for the File menu item. As you type the Caption value, notice that Visual Basic adds the caption in the Menu Editor's lower section. The Menu Editor's lower half displays the menu bar and the pull-down options as you add them to the menu. The Menu Editor's top half contains a description of individual items in the menu.
  3. Press Tab to move the focus to the Name text box, and type mnuFile. The application will refer to the File menu bar item by the name mnuFile as needed. In other words, just as a command button might be named cmdPressMe, the menu bar option can be named mnuFile. The three-letter prefix indicates that the mnuFile object is a menu item and not some other kind of control. Your Menu Editor's window should look something like the one in Figure 17.3.
    17fig03.gif

    Figure 17.3 The menu bar now has a defined File option.

    The only accelerator keystroke available for menu bar options is the underlined Alt+keystroke that occurs as the result of the Caption property's underlined letter. Don't attempt to select Ctrl+keystroke from the Shortcut drop-down list box for the menu bar options. Ctrl+keystroke shortcut combinations are available only for pull-down menu options. Don't press Enter or click the OK button to close the Menu Editor just yet; you need to add the additional menu bar options before closing the Menu Editor's window.

Share ThisShare This

Informit Network