1

It seems as though CTRL + E and CTRL + R (at the very least) don't get handled in the same way as other keyboard combinations. The E and the R respectively aren't recognized.

The way I've been testing this is to create a form with a TextBox and Button, then add the following:

private void button1_Click(object sender, EventArgs e)
{
    textBox1.ReadOnly = !textBox1.ReadOnly;
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    bool ctrl = ModifierKeys == Keys.Control;
    System.Diagnostics.Debug.WriteLine("Control pressed: " + e.Control + "    Key pressed: " + e.KeyData + "       Modifier Control pressed: " + ctrl);
}

When the TextBox is ReadOnly, only certain key combinations don't work. I added a context menu strip with an item for handling the desired keyboard combinations, but that interferes with the textbox's context menu (actually the DevEx spellchecker context menu I have associated with the TextBox)--it doesn't even display.

Does anyone know why or the best way to get around this? Thanks for any help you can give.

Phoenix
  • 1,045
  • 1
  • 14
  • 22
RobC
  • 1,303
  • 3
  • 15
  • 32
  • 1
    Try using ProcessCmdKey() instead. http://stackoverflow.com/questions/400113/best-way-to-implement-keyboard-shortcuts-in-a-windows-forms-application/400325#400325 By the way, what are Ctrl+E and Ctrl+R supposed to do? – RenniePet Aug 18 '14 at 19:57
  • Thanks for the link. I ended up overriding ProcessCmdKey in my DevEx MemoEdit. – RobC Aug 19 '14 at 13:25
  • Glad to help. If I post it as an answer do you give me brownie-points? :-) – RenniePet Aug 19 '14 at 14:32
  • @RenniePet: Absolutely. – RobC Aug 23 '14 at 12:23

1 Answers1

1

As the legendary Hans Passant points out on this thread, it is usually best to handle Ctrl+x keystrokes that are intended to provide a command-like function by using a ProcessCmdKey() method.

Glad it worked out for you.

Community
  • 1
  • 1
RenniePet
  • 11,420
  • 7
  • 80
  • 106