1

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?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Mike T
  • 482
  • 1
  • 6
  • 16
  • 3
    Is this a WinForms application? – John Saunders Apr 29 '15 at 22:16
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 29 '15 at 22:17
  • why don't you alter the code / functionality to make the forms popup as modal.. is there a reason for not doing so ..otherwise you could create some delegate event handlers ..just a thought.. – MethodMan Apr 29 '15 at 22:39
  • 1
    @JohnSaunders yes, this is WinForms. – Mike T Apr 30 '15 at 13:00

2 Answers2

2

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.

Community
  • 1
  • 1
Mike T
  • 482
  • 1
  • 6
  • 16
0

Option 1 (Quick & Dirty): In WinForm or WPF, create an eventlistener for keydown. In the code-behind

private void textBox1_keyDown(object sender, KeyEventArgs e)
{
    if (e.Control & e.KeyCode == Keys.A)
    {
        textBox1.SelectAll();
    }
}

Option 2: Inherit a textbox and override OnPreviewKeyDown

SILENT
  • 3,916
  • 3
  • 38
  • 57