Search code examples
c#.netwinformsmodeless

Parent window shortcut steals input from modeless child


I have an application with a parent window and the potential for multiple modeless windows to be pulled up from it.

In one of these modeless windows, there is a text box.

When typing in the textbox, I want to be able to hit CTRL+A to select all text.

However, my parent window has a menu item that specifies CTRL+A as its shortcut (it does it's own select-all sort of thing).

In the KeyDown event in my modeless textbox/control/form, I never see CTRL+A come through. In short, it is being stolen by the parent window. I want to override it to do something different in the modeless window. Alternatively, I want to override it to do nothing at all. If possible, how do I do this?


Solution

  • Found the answer here: Best way to implement keyboard shortcuts in a Windows Forms application?

    The trick is to override the ProcessCmdKey method and return true when you pick up on the desired input (Ctrl + A) in my case.