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

其中一個 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 指派給名為的功能表項目 printToolStripMenuItemThe following code example demonstrates how to use the ShortcutKeys property to assign the key combination CTRL+P to a menu item called printToolStripMenuItem. 如需完整範例,請參閱 如何:將 Web 瀏覽器功能新增至 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

備註

ShortcutKeys 可以使用屬性將按鍵組合指派給功能表命令,例如 CTRL + C 用於 複製 命令。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. 在程式碼中定義存取金鑰,方法是在您想要用於存取金鑰的字母之前輸入連字號 ( # A0) 。Define access keys in code by typing an ampersand (&) before the letter you want to use for an access key.

適用於

另請參閱