Adding Menu Enhancements to Windows Forms
There are four enhancements that can be added to menus to convey information to users.
- Check marks can be used to designate whether a feature is turned on or off (such as whether a ruler is displayed along the margin of a word-processing application) or to indicate which of a list of files is being displayed (such as on a Window menu).
- Shortcut keys are keyboard commands to access menu items within an application.
- Access keys allow keyboard navigation of menus (pressing the ALT key and the underlined access key chooses the desired menu or menu item).
- Separator bars are used to group related commands within a menu and make menus easier to read.
To add a check mark to a menu item at design time
- With the menu item selected within the Menu Designer, click the area to the left of the menu item.
A check mark appears, indicating the Checked property has been set to true.
– or –
- With the menu item selected within the Menu Designer, set the Checked property to true in the Properties window.
Note In lieu of setting the Checked property, you can set the RadioCheck property. When the RadioCheck property is set to true, a small dot (•) is displayed next to the menu item, indicating it is selected. For more information about the radio check marks and menus, see MainMenu Component.
To add a check mark to a menu item programmatically
- Within the method where you set the properties of the menu item (such as Text), add code to set the Checked property to true:
' Visual Basic myMnuItem.Checked = True // C# myMnuItem.Checked = true; // C++ myMnuItem->Checked = true;
To add a shortcut key to a menu item at design time
- Select the menu item within the Menu Designer. In the Properties window, set the Shortcut property to one of the values offered in the drop-down list.
To add a shortcut key to a menu item programmatically
- Within the method where you set the properties of the menu item (such as Text), add code to set the Shortcut property to one of the values of the Shortcut enumeration:
' Visual Basic myMnuItem.Shortcut = System.Windows.Forms.Shortcut.F6 // C# myMnuItem.Shortcut = System.Windows.Forms.Shortcut.F6; // C++ myMnuItem->Shortcut = System::Windows::Forms::Shortcut::F6;
To add an access key to a menu item
- When setting the Text property (either in the Properties window, in the Menu Designer, or in code), enter an ampersand (&) prior to the letter you want to be underlined as the access key. For example, typing
F&ormatas the Text property of a menu item will result in a menu item that appears as Format.
To navigate to this menu item, press ALT to give focus to the menu bar, and press the access key of the menu name. When the menu opens and shows items with access keys, you only need to press the access key to select the menu item.
To add a separator bar as a menu item
- In the Menu Designer, right-click the location where you want a separator bar, and choose New Separator.
- When setting the Text property (either in the Properties window, in the Menu Designer, or in code) of the menu item, enter a dash (–) to make that menu item a separator bar.