
62
❘
LESSON 5 Making Menus
2. Add a TextBox to the form. Type some text into its Text property and set its other
properties:
Name = txtContents, MultiLine = True, Dock = Fill, ScrollBars = Both.
3. Create the context menu by double-clicking the Toolbox’s ContextMenuStrip tool.
Create the main menu structure.
➤
1. Select the MenuStrip. Click the Type Here box and type &File.
2. In the Type Here box below the File menu, type E&xit.
By convention, the Exit command uses X as its accelerator. It never has a short-
cut because it would be too easy to accidentally close the program while banging
your head on the keyboard. (Or if you fat-finger the keys, the keyboard is hit by a
flying tennis ball, your cat walks across the keyboard, and so on.)
3. Click the File item again. In the Type Here box to the right, type F&ormat.
4. Use the Type Here boxes below the Format menu to create the format menu items and
their submenus.
5. Use the Properties window to set the font sizes for the Font menu’s Small, Normal, and
Large items to 6, 9, and 20.
6. Give the Color and Font submenu items appropriate shortcuts.
7. Give the menu items that take action appropriate names. For example, name the Font
menu’s Small item
formatFontSmallMenuItem.
Add code behind the main menu items.
➤
1. Double-click the Exit menu item and type the bold line in the following code so the
event handler looks like ...