TX Text Control Blog

Overriding IE's predefined shortcuts like CTRL-B

Blogged by Björn Meyer on October 7, 2009 and tagged with browsertextcontrol.

CTRL-B is the de facto standard shortcut for making a selection bold in word processing applications. When trying to implement that into a BrowserTextControl based user control that is used in Internet Explorer, IE opens the Organize Favorites dialog. I admit that this might be confusing to the user.

The technical part: If the command key is not a menu shortcut of the user control and the control has a parent (in the simplest case IE itself), the key is bubbled up to the parent's ProcessCmdKey method.

To overcome this 'feature' of Internet Explorer, it is not enough to handle the KeyPress or KeyDown events in TX Text Control. TX Text Control will never receive the messages from IE.

What we need to do is to override the ProcessCmdKey method to handle the keys directly. You simply need to add the following method to your user control in order to handle CTLR-B and CTRL-I.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { Keys key = keyData & ~(Keys.Shift | Keys.Control); switch (key) { case Keys.B: if ((keyData & Keys.Control) != 0) { browserTextControl1.Selection.Bold = !browserTextControl1.Selection.Bold; return true; } break; case Keys.I: if ((keyData & Keys.Control) != 0) { browserTextControl1.Selection.Italic = !browserTextControl1.Selection.Italic; return true; } break; } return base.ProcessCmdKey(ref msg, keyData); }
 
 
 

Products

Support

Downloads

Corporate

Buy Now