102 Part I Getting Started with Microsoft Visual Basic 2010
Now you’ll practice using the Menu Designer to switch the order of the Date and Time
commands on the Clock menu. Changing the order of menu items is an important skill
because at times you’ll think of a better way to define your menus.
Change the order of menu items
- Click the Clock menu on the form to display its menu items.
To change the order of a menu item, simply drag the item to a new location on the
menu. Try it now.
- Drag the Time menu on top of the Date menu, and then release the mouse button.
Dragging one menu item on top of another menu item means that you want to place
the first menu item ahead of the second menu item on the menu. As quickly as that,
Visual Studio moved the Time menu item ahead of the Date item.
You’ve finished creating the user interface for the Clock menu. Now you’ll use the menu
event procedures to process the user’s menu selections in the program.
Note To delete a menu item from a menu, click the unwanted item in the menu list, and then press
the DELETE key. (If you try this now, remember that Visual Studio also has an Undo command, located
on both the Edit menu and the Standard toolbar, so you can reverse the effects of the deletion .)
Processing Menu Choices
After menus and commands are configured by using the menu strip object, they also
become new objects in your program. To make the menu objects do meaningful work, you
need to write event procedures for them. Menu event procedures typically contain program
statements that display or process information on the user interface (UI) form and modify
one or more menu properties. If more information is needed from the user to process
the selected command, you can write your event procedure so that it displays a dialog box
and one or more of the input controls you used in Chapter 3.
In the following exercise, you’ll add a label object to your form to display the output of the
Time and Date commands on the Clock menu.
Add a label object to the form
- Click the Label control in the Toolbox.
- Create a label in the middle of the form.
The label object appears on the form and displays the name Label1 in the program code.