Tuesday, March 1, 2011

RichTextBox CtrlI

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?

From stackoverflow
  • 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);
      }
    }
    
    Jake Pearson : Thanks, that did the trick!

0 comments:

Post a Comment