Introducing the Menu Editor Window


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.

Figure 5.1

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.

Example

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:

  1. Type Fly in the Caption field.
  2. Type mnuFly in the Name field.
  3. Click the Next button without entering other Menu Editor values, because the Fly menu bar item is already complete. Notice that clicking Next moves the highlight bar down the Menu control list box area.
  4. Type Delta for the next Caption and mnuFlyDelta for the name and click Next. Your Menu Editor window should now look like the one in Figure 5.3.

Figure 5.2

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.

  1. Click OK to see the menu as it appears so far (see Figure 5.3).

Figure 5.3

The menu bar as it appears so far.

  1. Because Delta is directly beneath Fly in the Menu Editor's control list box area, Visual Basic thinks Delta is a menu bar item instead of a submenu item (as you can see by the menu bar shown in Figure 5.3). However, Delta is supposed to appear as an option on Fly's pull-down menu. Indentation tells the Menu Editor which items are menu bar items and which are submenu items. If you indent Delta to the right, the Menu Editor knows that Delta is a submenu item for Fly.
  2. Open the Menu Editor again and click the row with Delta.
  3. Click the right arrow button. The Menu Editor indents Delta to the right, showing that Delta is now a submenu item under Fly.
  4. If you ever need to turn a submenu item into a menu bar item, click the left arrow's button to move that submenu item up to the menu bar. Also, the up and down arrow buttons move items up or down the menu without changing the item's subornation to other menu items. You can also use the Insert and Delete buttons (as explained in Table 5.1) to insert and delete items from the menu. Next simply moves the highlight down the list.
  5. Continue building the menu with Table 5.2's entries until you've added all the Fly submenu items. Your Menu Editor window should look like the one in Figure 5.4.

Figure 5.4

You've now entered all the first menu's items.

  1. With the highlight in the new position under your menu items, click the left arrow button to move the subordination up a level so you can enter the second menu bar item.
  2. Type Drive in the Caption text box and mnuDrive in the Name text box. Make sure that Drive aligns with Fly at the left of the Menu Editor, so they both appear on the menu bar.
  3. Enter the rest of the menu items. When you finish, your Menu Editor should look like Figure 5.5. Make sure that your Menu Editor's indention matches that of Figure 5.5's. If you've added a blank, indented menu item at the bottom of the Menu Editor, highlight the blank item and click Delete.

Figure 5.5

You've completed the menu structure.