
Making Menus
In addition to buttons, labels, and textboxes, menus are one of the most common user inter-
face elements in interactive programs.
This lesson explains how to add menus and context menus to forms and catch their events so
your program can take action when the user selects menu items.
CREATING MENUS
To create a menu, simply drop a MenuStrip control on a form. By default, the MenuStrip is
docked to the top of the form so you don’t really need to position it carefully. Just double-click
the Toolbox’s
MenuStrip tool and you’re set.
Unlike most controls, the
MenuStrip appears in the
Component Tray below the form in addition to on the
form itself. Figure 5-1 shows the SimpleEdit program
in the Form Designer. Below the form you can see
the Component Tray containing a
MenuStrip and a
StatusStrip.
When you select a
MenuStrip in the Form Designer, the
menu bar at the top of the form displays a Type Here
box. Click that box and type the menu’s caption to cre-
ate a main menu.
If you create a main menu entry and select it, the Form
Designer displays a new Type Here box to let you create
menu items (see Figure 5-2).
Continue entering text in the Type Here boxes to build
the whole menu structure. Figure 5-3 shows the Edit
menu for a new version of the SimpleEdit program.
Notice that the menu contains several cascading sub-
menus. The Offset submenu is expanded in Figure 5-3.
FIGURE 51
5
596906c05.indd ...