Visual Basic Concepts
You can use the Menu Editor to create new menus and menu bars, add new commands to existing menus, replace existing menu commands with your own commands, and change and delete existing menus and menu bars.
To display the Menu Editor
or
Click the Menu Editor button on the toolbar.
This opens the Menu Editor, shown in Figure 6.7.
Figure 6.7 The Menu Editor
While most menu control properties can be set using the Menu Editor, all menu properties are available in the Properties window. The two most important properties for menu controls are:
Other properties in the Menu Editor, including Index, Checked, and NegotiatePosition, are described later in this chapter.
The menu control list box (the lower portion of the Menu Editor) lists all the menu controls for the current form. When you type a menu item in the Caption text box, that item also appears in the menu control list box. Selecting an existing menu control from the list box allows you to edit the properties for that control.
For example, Figure 6.7 shows the menu controls for a File menu in a typical application. The position of the menu control in the menu control list box determines whether the control is a menu title, menu item, submenu title, or submenu item:
Note A menu control cannot be a separator bar if it is a menu title, has submenu items, is checked or disabled, or has a shortcut key.
To create menu controls in the Menu Editor
or
Click the Menu Editor button on the toolbar.
The menu title text is displayed in the menu control list box.
or
Click Insert to add a menu control between existing controls.
You can also click the up arrow and down arrow buttons to move the control among the existing menu controls.
The menu titles you create are displayed on the form. At design time, click a menu title to drop down its corresponding menu items.
A separator bar is displayed as a horizontal line between items on a menu. On a menu with many items, you can use a separator bar to divide items into logical groups. For example, the File menu in Visual Basic uses separator bars to divide its menu items into three groups, as shown in Figure 6.8.
Figure 6.8 Separator bars
To create a separator bar in the Menu Editor
Note Although separator bars are created as menu controls, they do not respond to the Click event, and users cannot choose them.
You can improve keyboard access to menu commands by defining access keys and shortcut keys.
Access keys allow the user to open a menu by pressing the ALT key and typing a designated letter. Once a menu is open, the user can choose a control by pressing the letter (the access key) assigned to it. For example, ALT+E might open the Edit menu, and P might select the Paste menu item. An access-key assignment appears as an underlined letter in the menu control's caption, as shown in Figure 6.9.
Figure 6.9 Access keys
To assign an access key to a menu control in the Menu Editor
For example, if the Edit menu shown in Figure 6.9 is open, the following Caption property settings respond to the corresponding keys.
Menu control caption | Caption property | Access keys |
Cut | Cu&t | t |
Copy | C&opy | o |
Paste
Delete Select All Time/Date |
&Paste
De&lete Select &All Time/&Date |
p
l a d |
Note Do not use duplicate access keys on menus. If you use the same access key for more than one menu item, the key will not work. For example, if C is the access key for both Cut and Copy, when you select the Edit menu and press C, the Copy command will be selected, but the application will not carry out the command until the user presses ENTER. The Cut command will not be selected at all.
Shortcut keys run a menu item immediately when pressed. Frequently used menu items may be assigned a keyboard shortcut, which provides a single-step method of keyboard access, rather than a three-step method of pressing ALT, a menu title access character, and then a menu item access character. Shortcut key assignments include function key and control key combinations, such as CTRL+F1 or CTRL+A. They appear on the menu to the right of the corresponding menu item, as shown in Figure 6.10.
Figure 6.10 Shortcut keys
To assign a shortcut key to a menu item
To remove a shortcut key assignment, choose "(none)" from the top of the list.
Note Shortcut keys appear automatically on the menu; therefore, you do not have to enter CTRL+key in the Caption box of the Menu Editor.