Creating Shortcut Keys

Unlike access keys, shortcut keys are a combination of keystrokes that allow direct invocation of a menu item whether the menu item is visible or not. For example, you might define the Ctrl+E key combination to be a shortcut key for the Exit menu command in the File menu. Even if the File menu is not open, Ctrl+E will cause the Exit menu command to be executed. Also, unlike access keys, you cannot create shortcut keys for top-level menus—you can create them only for items in sub-menus.

You can create a shortcut key at design time by setting the ShortcutKeys property in the Properties window. Clicking the ShortcutKeys property launches a visual interface than enables you to define a key combination. This interface is shown in Figure 4-5.

If you want to display the shortcut key combination next to the menu item, you can set the ShowShortcutKeys property of the ToolStripMenuItem control to True. You can also define a custom text to be shown instead of the key combination. If you want to define a custom text, you can set it in the ShortcutKeyDisplayString property.

OpenToolStripMenuItem System,Windows.Forms,ToolStripMeni. •

DisplayStyle DoubleClickEnabled DropDown DropDownltems Enabled El Font ForeColor GenerateMember Image ImageAlign ImageSealing ImageTransparentColor El Margin MergeAction Mergelndex Modifiers Overflow El Padding RightToLeft

RightToLeftAutoMirrorlmage ShortcutKeyDisplayString


(none) (Collection)

Tahomaj 8.25pt ControlText






The shortcut key associated"


^•Properties ^Solution Explorer

Figure 4-5 The ShortcutKeys property user interface

0 0

Post a comment