Visual Basic forms can have menu bars similar to those in most Windows applications. Figure 9.11 shows





The MenuStrip Control
Visual Basic forms can have menu bars similar to those in most Windows applications. Figure 9.11 shows a typical menu, with the Order menu revealed. Here, the menu bar contains two menu items (Order and Color), referred to as top-level menu items. When the Order menu item is clicked, a dropdown list containing two second-level menu items (Ascending and Descending) appears. Although not visible here, the dropdown list under Color contains the two second-level menu items Foreground and Background. Each menu item is treated as a distinct control that responds to a click event. The click event is triggered not only by the click of the mouse button, but also for top-level items by pressing Alt + accesskey and for second-level items by just pressing the access key. The event procedure for the Ascending or Descending menu item also can be triggered by pressing the shortcut key combination Ctrl + A or Ctrl + D.
Menus are created with the MenuStrip control, which is usually the third control in the Menus & Toolbars section of the Toolbox. Each menu item has a Text property (what the user sees) and a Name property (used to refer to the item in the code.) The following steps are used to create the Order-Color menu:
1. Start a new project.
2. Double-click on the MenuStrip control in the Toolbox. The control appears in a pane below the Main area, and a menu designer appears just below the title bar in the Form designer. See Figure 9.12.
3. Click on the rectangle that says "Type Here", type in the text &Order, and press the Enter key. (The ampersand specifies O as an access key for the menu item.)

"Type Here" rectangles appear below and to the right of the Order menu item. The rectangle below is used to create a second-level item for the Order menu. The rectangle on the right is used to create a new first-level menu item.
4. Type the text "&Ascending" into the rectangle below the Order rectangle, and press the Enter key.
5. Click on the Ascending menu item to display its Property window. In the Property window, change the name property of the menu item from AscendingToolStripMenuItem to mnuOrderAsc. Also, click on the down-arrow at the right of the ShortcutKeys setting box, click on the "Ctrl" Modifier check box, select "A" from the Key drop-down combo box, and then press the Enter key. (When the program is run, "Ctrl + A" will appear to the right of the word "Ascending".)
6. Type "&Descending" into the rectangle below the Ascending rectangle, set the Name property of the Descending menu item to mnuOrderDesc, and set the ShortcutKeys Property to Ctrl + D.
7. Click on the rectangle to the right of the Order rectangle and enter the text "&Color".
8. Type "&Foreground" into the rectangle below the Color rectangle, and set its Name property to mnuColorFore.
9. Type "&Background" into the rectangle below the Foreground rectangle, and set its Name property to mnuColorBack.
10. Click on the Foreground rectangle, and type "&Red" into the rectangle on its right. (We have just created a third-level menu item.) Set its Name property to mnuColorForeRed.
11. Type "&Blue" into the rectangle below the Red rectangle, and set its Name property to mnuColorForeBlue.
12. Click on the Background rectangle, type "&Yellow" into the rectangle on its right, and set its Name property to mnuColorBackYellow.
13. Type "&White" into the rectangle below the Yellow rectangle, and set its Name property to mnuColorBackWhite. Then set its Checked property to True. A check mark will appear to the left of the word "White."
14. Run the program; click on Order to see its menu items; click on Color and hover over the word Foreground to see its menu items. Each menu item has a Click event procedure. The menu items are only useful after we write code for the relevant event procedures