ToolStripMenuItem.ShortcutKeys 屬性

定義

取得或設定與 ToolStripMenuItem 關聯的快速鍵。Gets or sets the shortcut keys associated with the ToolStripMenuItem.

public:
 property System::Windows::Forms::Keys ShortcutKeys { System::Windows::Forms::Keys get(); void set(System::Windows::Forms::Keys value); };
public System.Windows.Forms.Keys ShortcutKeys { get; set; }
member this.ShortcutKeys : System.Windows.Forms.Keys with get, set
Public Property ShortcutKeys As Keys

屬性值

其中一個 Keys 值。One of the Keys values. 預設為 NoneThe default is None.

例外狀況

屬性未設定為其中一個 Keys 值。The property was not set to one of the Keys values.

範例

下列程式碼範例示範如何使用ShortcutKeys屬性,將按鍵組合 CTRL + P 指派給名printToolStripMenuItem為的功能表項目。The following code example demonstrates how to use the ShortcutKeys property to assign the key combination CTRL+P to a menu item called printToolStripMenuItem. 如需完整範例,請參閱如何:將網頁瀏覽器功能新增至 Windows Forms應用程式。For the complete example, see How to: Add Web Browser Capabilities to a Windows Forms Application.

printToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
printToolStripMenuItem.ShortcutKeys = Keys.Control Or Keys.P

備註

您可以使用 屬性,將按鍵組合指派給功能表命令,例如,CTRL+C用於複製ShortcutKeys命令。Use the ShortcutKeys property to assign a key combination to a menu command, such as CTRL+C for the Copy command. 除了存取金鑰以外,您還可以使用快速鍵,而不是便捷鍵,也就是與 ALT 鍵搭配使用的功能表或功能表項目中的加上底線的字母。You can use shortcut keys instead of or in addition to access keys, which are underscored letters in menus or menu items used with the ALT key. 在程式碼中定義存取金鑰,方法是在您想要用於存取金鑰的字母之前輸入連字號(&)。Define access keys in code by typing an ampersand (&) before the letter you want to use for an access key.

適用於

另請參閱