JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Menu Shortcuts

You can create shortcuts for menu items, which are key combinations that, when pressed, will select that item, making its Click event happen. You set a shortcut with the Shortcut property. To display the shortcut next to the menu item's caption at run time, you set the ShowShortcut property to True (it's True by default).

For example, in the Menus example on the CD-ROM, I've given the Exit item in the File menu a shortcut of Ctrl+X, as you can see next to its caption in Figure 9.1. When the user presses Ctrl+X, this item is activated. To assign a shortcut key combination to a menu item at design time, just select a shortcut key combination from the list that appears when you select the Shortcut property of any menu item in the properties window. At run time, you can use members of the Shortcut enumeration to do the same thing, as in this code:

menuItem1.Shortcut = Shortcut.CtrlX

Bear in mind that shortcuts will select their corresponding menu item even if no menu is open at the time. If you want to make sure the user must first open the item's menu, use access keys instead; see the previous topic.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor