In a simple dialog app, using designer, I’ve set up the usual shortcut keys for cut, copy, paste and delete in the edit menu.
My problem is that I only want to handle delete events when a certain tree control is in focus. Otherwise, in my datagrid control for example, I want delete to work as usual.
What’s the best way to do this? Currently I’m getting a delete event in the main form class, but the delete key isn’t working in the edit controls in the datagrid control.
Edit – specified that the delete key isn’t working in edit sub-controls
It seems that if you want to use the shortcut keys for menu items, that
keycombinationis taken throughout your form, no matter if you set up youreventhandlerto not do anything unless a certain tree control is in focus (there is no way to set the key-event as.Handled=false).So the best way would be to NOT set the shortcut-key in the menu-strip, but instead hook the
KeyDownevent on the form (keypreview) or on the specific tree control, and handle whatever the delete shortcut key should do there.If you need the shortcut text to show even though you have no shortcut key defined in the menu-strip, use the
.ShortcutKeyDisplayStringproperty on the menu item to set a text.