Export (0) Print
Expand All

MenuItem.Shortcut Property

Gets or sets a value indicating the shortcut key associated with the menu item.

[Visual Basic]
Public Property Shortcut As Shortcut
[C#]
public Shortcut Shortcut {get; set;}
[C++]
public: __property Shortcut get_Shortcut();
public: __property void set_Shortcut(Shortcut);
[JScript]
public function get Shortcut() : Shortcut;
public function set Shortcut(Shortcut);

Property Value

One of the Shortcut values. The default is Shortcut.None.

Remarks

Shortcut keys provide a method for users to activate frequently used menu items in your menu system and to provide keyboard access to your application for those users who do not have access to a mouse or other pointer device.

Example

[Visual Basic, C#, C++] The following example creates a menu item, sets the caption, assigns a shortcut key, makes the menu item visible, and shows the shortcut key display for the menu item. The example assumes a MenuItem object has been created that is named menuItem1.

[Visual Basic] 
Public Sub SetupMyMenuItem()
    ' Set the caption for the menu item.
    menuItem1.Text = "&New"
    ' Assign a shortcut key.
    menuItem1.Shortcut = Shortcut.CtrlN
    ' Make the menu item visible.
    menuItem1.Visible = True
    ' Display the shortcut key combination.
    menuItem1.ShowShortcut = True
End Sub


[C#] 
public void SetupMyMenuItem()
{
   // Set the caption for the menu item.
   menuItem1.Text = "&New";
   // Assign a shortcut key.
   menuItem1.Shortcut = Shortcut.CtrlN;
   // Make the menu item visible.
   menuItem1.Visible = true;
   // Display the shortcut key combination.
   menuItem1.ShowShortcut = true;
}
  

[C++] 
public:
 void SetupMyMenuItem()
 {
    // Set the caption for the menu item.
    menuItem1->Text = S"&New";
    // Assign a shortcut key.
    menuItem1->Shortcut = Shortcut::CtrlN;
    // Make the menu item visible.
    menuItem1->Visible = true;
    // Display the shortcut key combination.
    menuItem1->ShowShortcut = true;
 }
   

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace | Shortcut

Show:
© 2014 Microsoft