将Windows窗体ToolStripMenuItem ShortcutKeys属性设置为numpad键不起作用 [英] Setting the Windows Forms ToolStripMenuItem ShortcutKeys property to numpad key does not work
问题描述
我们能够为Windows Forms应用程序菜单项定义快捷键.这样,我可以告诉菜单项 File-> Save 具有快捷键 Ctrl + S ,并且菜单项的处理程序是神奇的"在按 Ctrl + S 后执行.
We have the ability to define shortcut keys for Windows Forms application menu items. That way I can tell a menu item File->Save to have the shortcut key Ctrl + S and the menu item's handler is "magically" executed after pressing Ctrl + S.
问题出在数字小键盘键上,ShortcutKey
属性不接受它们(我不知道它们与其他可接受的键有何不同).
The trouble is with the numeric keypad keys, the ShortcutKey
property does not accept them (I don't understand how are they different from the other acceptable keys).
MSDN声明该属性接受类型 System.Windows.Forms.Keys (键"值之一.默认值为无").当参数不是 Keys 值之一时,将抛出InvalidEnumArgumentException
.但例如,Keys.Divide IS 是Keys值之一,但无法使用.
MSDN states that the property accepts type System.Windows.Forms.Keys (One of the Keys values. The default is None.); and an InvalidEnumArgumentException
would be thrown when the parameter is not one of Keys values. But for example Keys.Divide IS one of Keys values, and yet it can't be used.
那么如何设置菜单项以具有Numpad *
或Numpad +
的快捷方式?我是否需要处理Form的 ProcessCmdKey 事件中的键?
So how can I set a menu item to have a shortcut for Numpad *
or Numpad +
? Do I need to handle the key in Form's ProcessCmdKey event?
推荐答案
您必须在快捷方式中使用 Ctrl 或 Alt .
You must use Ctrl or Alt in shortcuts.
示例:
//working:
toolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.NumPad0;
//throws exception
toolStripMenuItem1.ShortcutKeys = Keys.NumPad0;
这篇关于将Windows窗体ToolStripMenuItem ShortcutKeys属性设置为numpad键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!