The Menu Editor is a dialog box that helps you design and create menus. Surprisingly, Microsoft hasn't changed the Menu Editor much in several years. (The Menu Editor has existed in many Microsoft products, including previous versions of Visual Basic and Visual C++.) The length of time that Microsoft has used the Menu Editor, and that the Menu Editor has remained relatively unchanged, is a testament to the Menu Editor's ease and power.
Menus appear on forms. Your application can contain a single form or multiple forms. You can place a menu on any or all of the forms. You can't access the Menu Editor until you display a form in your Form window. The Menu Editor then creates a menu for that form.
The Menu Editor makes it easy to change your mind. If you don't like the menu that you created, you can change it. You easily can add or remove menu items later as your application's needs change.
![]()
To invoke the Menu Editor, choose Menu Editor from theTools menu; press Ctrl+E; or click the toolbar's Menu Editor button. Figure 5.1 shows the Menu Editor.
Create and edit menus in the Menu Editor.
Menu control properties
Menu control list box
The top half of the Menu Editor, called the Menu control properties area, lets you set specific properties about your menu items and the overall menu bar. The large blank area at the bottom of the Menu Editor, the Menu control list box, displays the current menu structure as you build the menu. Table 5.1 describes the options you'll find on the Menu Editor.
Table 5.1 The Menu Editor's Options
Option | Description |
Caption | The menu item name that you want to appear on the menu bar |
Name | A control name that you assign to each menu item |
Index | A value you assign if you create a menu control array, which lets you work with multiple menu items simultaneously through programming code |
Shortcut | The Ctrl-keystroke combination that triggers the current menu item |
HelpContextID | A reference value that lets you connect online help to each menu item |
NegotiatePosition | A reference value that determines how and where the menu item falls within a special container form, where you can store a repository of controls |
Checked | An option that determines whether a check mark appears to the left of menu items (choose Toolbars from VB's View menu for an example) |
Enabled | An option that determines whether the menu option is temporarily disabled (indicated by the option being grayed out) |
Visible | An option that determines whether the menu item is now visible or hidden on the menu |
WindowList | An MDI (Multiple Document Interface) option that determines whether the menu contains open MDI forms |
Arrow buttons | Controls that let you change the indention level of selected menu items |
Next | A command button that moves the selected menu item in the Menu control list box to the next line |
Insert | A command button that lets you insert new menu items between two existing items |
Delete | A command button that lets you remove menu items you no longer want |
One of the best ways to learn the Menu Editor is to use it. The following example builds an imaginary menu structure. Because the menu you build isn't going to conform to any Windows menu bar standards, you can concentrate on the Menu Editor and not worry about programming details.
Create a new project so that you can practice with the Menu Editor. Choose Standard EXE from the New Project dialog box; Visual Basic creates the sample form named Form1 for you. For this example, don't worry about renaming the form because you'll discard it after you're done.
Table 5.2 describes the menu structure you're going to create in this example.
Table 5.2 The Example's Menu Structure
Menu Name | Menu Option | Name | Event Procedure |
Fly | mnuFly | ||
Fly | Delta | mnuFlyDelta | mnuFlyDelta_Click |
Fly | American | mnuFlyAmerican | mnuFlyAmerican_Click |
Fly | United | mnuFlyUnited | mnuFlyUnited_Click |
Fly | Southwest | mnuFlySouthwest | mnuFlySouthwest_Click |
Drive | mnuDrive | ||
Drive | Truck | mnuDriveTruck | mnuDriveTruck_Click |
Drive | Car | mnuDriveCar | mnuDriveCar_Click |
Drive | Tractor | mnuDriveTractor |
mnuDriveTractor_Click |
At first, you may not understand how all of Table 5.2's columns work together to create a menu, but they make sense when you think of how menu structures often appear:
Search Visual Basic's Books Online for Menu Title and Naming Guidelines for additional menu option naming conventions you should follow.
![]()
Although the menu item and event names are lengthy, you'll be able to remember them when you begin programming their events because their names describe exactly which menu bar items and options they refer to.
![]()
Follow these steps to create a menu with the Menu Editor:
The sample menu is taking shape.
Don't be confused that you didn't type Fly again for the Menu Name. Fly is a menu bar item, but Delta won't be after you fix the menu in a later step.
![]()
The menu bar as it appears so far.
You've now entered all the first menu's items.
You've completed the menu structure.