Question

I have a RichTextBox in .NET WinForms. I have been hooking up hot keys with KeyUp. Everything is working fine, except for CtrlI. By the time my handler gets its turn, the selection has been replaced with a '\t'. I turned off ShortcutsEnabled, but it didn't make any difference. Any ideas?

Was it helpful?

Solution

Do it like this:

using System;
using System.Windows.Forms;

public class MyRtb : RichTextBox {
  protected override bool ProcessCmdKey(ref Message m, Keys keyData) {
    if (keyData == (Keys.I | Keys.Control)) {
      // Do your stuff
      return true;
    }
    return base.ProcessCmdKey(ref m, keyData);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top