Delete from the "Edit" menu
In a simple dialog application, using the designer, I set up the usual cut, copy, paste, and delete keyboard shortcuts in the edit menu.
My problem is that I only want to handle delete events if a particular tree control has focus. Otherwise, for example in my datagrid control, I want the deletion to work as usual.
What's the best way to do this? I am currently receiving a delete event on the main class of the form, but the delete key is not working on edit controls in the datagrid control.
Edit - indicated that the delete key does not work in the edit submenu
source to share
It looks like if you want to use keyboard shortcuts for menu items, then it keycombination
is taken across your entire form, regardless of whether you configure it eventhandler
to do nothing, unless a certain tree control is in focus (it is impossible to set a key event as .Handled=false
).
So the best way would be to not set the shortcut in the menu bar, but instead intercept the event KeyDown
in the form ( keypreview
) or in a specific tree control and handle any remote there should be a shortcut key.
If you need shortcut text to show, even if you don't have a shortcut key defined in the menu bar, use a property .ShortcutKeyDisplayString
on the menu item to set the text.
source to share