I am writing a winforms application and one of the functions is to open an item's properties. I'm not able to find out how to handle this. A menu item doesn't allow to define such a keyboard shortcut and implementing the handler manually with the keyup or keypress event handlers doesn't work either. Anyone out there who knows how to do this?
A:
I think you can define such a shortcut on a ToolStripMenuItem, but not on a MenuItem
implementing the handler manually with the keyup or keypress event handlers doesn't work either.
That's weird... can you show the code ?
Thomas Levesque
2009-06-05 14:58:13
i can dig out the code when I'm in the office again but the result was, that the menu in the menubar was selected as soon as the ALT key was pressed. Do you have some working code? Maybe I'm handling it in the wrong event handler...
Stefan Koell
2009-06-05 15:13:53
+1
A:
I think Thomas is correct, you must use a ToolStripMenuItem. Adding the following line to my .designer file worked like a champ:
this.fileProperties.ShortcutKeys = System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.Enter;
The keystroke works and the string "Alt + Enter" is displayed on the menu item.
NascarEd
2009-06-05 15:23:16
Never thought of that solution. Sometimes the simplest is the best.
Stefan Koell
2009-06-06 13:03:09