views:

64

answers:

1

Hi,

I have a ToolStripComboBox in a ToolStrip, and when I press TAB key in it, it gives focus to the next toolstrip button. I would like to change this behavior and give focus to a richtextbox on my form instead.

The problem is that ToolStripComboBox does not have PreviewKeyDown event. And PreviewKeyDown of the hosting ToolStrip Toolbar is not called when tab key is pressed in the combo (just when pressed and some toolstripbutton is focused).

TabStop of the toolstrip toolbar is false.

Any ideas?

A: 

You can catch this at the form level, before the ToolStrip control grabs the key. Override the form's ProcessCmdKey() method, make it look similar to this:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == Keys.Tab && this.ActiveControl == toolStripComboBox1.Control) {
            richTextBox1.Focus();
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
Hans Passant