[RESOLVED] Wiring more than one shortcut key to a single menu item
Yet another "request for comments" of mine... However, I think I may post it; the last one was about 6 weeks ago...
My intention is to invoke a menu item's click handler in response to more than a single shortcut key (combination). (The name of the respecitve ToolStripMenuItem property ShortcutKeys is a bit misleading. They probably named it like that because a shortcut usually is a combination of a base key and modifiers.) I have written the following class for that purpose:
The original idea behind this initiated in a form where I want to (almost) always dispatch the clipboard-related keyboard commands to the same single control, which is handled by the menu item click handlers of the edit menu.
It seems to work fine for now, unless the menu item click handler opens a message box (or probably does anything else that causes the app to enter a modal state). In this case it's the message box that consumes the unsuppressed KeyPressed event resluting from the key press that caused my handler to be invoked from the KeyDown handler and forwards that KeyPressed event to the focused control (a text box in my test app) on the form in question, bypassing my handlers.
This is the major known problem with this approach as of now. Of course I can strive to avoid entering a state like this from my menu item click handler, and in the real-life app this is originally designed for this can only happen under exceptional circumstances (which is to be taken literally: i.e. when an exception gets thrown). However, this is intended to be designed with the goal of reusability, and so I'd love to be able to sweep this situation wholesale.
Of course, as always, any comments about the class design and the approach as such are welcome!
Last edited by Eri523; July 22nd, 2011 at 11:25 AM.
Reason: Minor cosmetic code fix
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.