🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Windows Forms - MDI parent/child keypress event issue

Started by
0 comments, last by GuyWithBeard 8 years, 3 months ago

Hi,

I have a winforms app consisting of a main form + a number of child forms. The child forms can be floating windows, or they can be docked within the main form. I am using DockPanel Suite for this: http://dockpanelsuite.com/

The main form has a menu strip where certain menu items have keyboard shortcuts, eg. the Delete key is the shortcut for the "delete object" menu item.

This works well in with all child forms except for one, which has a scintilla.net text editor control inside it. The scintilla control has support built-in for keyboard shortcuts such as Ctrl-C and Delete. When this particular child form is highlighted and the user presses the Delete key to delete the characters to the right of the caret the main form fires the "delete object" menu item in the menu strip of the main form. This is obviously not what I want.

What would be the correct way to prevent the main form from firing the keyboard shortcuts in the main form menu strip if that one particular child form is active, ie. to let the text editor component react to the keyboard shortcuts without any other parts of the UI intercepting the events?

I have verified that the child control handles the key presses correctly if it is a floating window, in which case the main form is not active when the child form is active. The problem occurs only when the child form is nested inside the main form.

Thanks!

Advertisement
Actually, I think I came up with something. I override the ProcessCmdKey() method for the main form and have it check if the script child window is active. If it is, and the keys about to be processed are one of the conflicting menu item shortcuts, the the method just returns false. That prevents the shortcut event from being fired.
Using this I still need to handle all problematic keyboard shortcuts in the ProcessCmdKey() method, but I think I can live with that for now.

This topic is closed to new replies.

Advertisement