Products Technologies Demo Docs Blog Support Company

Overriding IE's Predefined Shortcuts Like CTRL-B

Internet Explorer intercepts CTRL-B and CTRL-I when a BrowserTextControl is hosted in a user control, triggering browser dialogs instead. Overriding ProcessCmdKey in the user control captures these shortcuts before IE handles them, applying bold or italic formatting to the selection.

Overriding IE's Predefined Shortcuts Like CTRL-B

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);
}

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

BrowserTextControl

TX Text Control Security Wizard Available

A downloadable Security Wizard application simplifies .NET Code Access Security configuration for BrowserTextControl in Internet Explorer. Deployed via ClickOnce, the tool runs with elevated…


BrowserTextControlSampleVisual Studio

BrowserTextControl: Using Post-build Events in Visual Studio

During BrowserTextControl development on a local machine, Internet Explorer caches the user control and skips re-downloading it when the codebase changes. Adding gacutil.exe /cdl as a Visual…


BrowserTextControlServerTextControl

BrowserTextControl: Compressed File Transfer

TX Text Control Server for ASP.NET 14.0 replaces .NET remoting with a new file I/O model for BrowserTextControl. ServerTextControl converts MS Word documents to byte arrays, which are sent to the…


BrowserTextControl

Activating the BrowserTextControl Automatically

Internet Explorer requires users to manually click embedded .NET controls before interacting with them. This workaround loads an external JavaScript file that dynamically creates and appends the…


BrowserTextControl

ASP.NET: Getting the Client's .NET Version

TX Text Control Server for ASP.NET requires .NET Framework on the client machine for BrowserTextControl. This article shows how to detect installed .NET versions server-side by parsing the…

Share on this blog post on: