MusiGenesis
MusiGenesis

Reputation: 75396

How do I hook the TAB key in a usercontrol so that focus doesn't move to a different control?

I have a usercontrol that is meant to take up the entire form. I want my usercontrol to handle the TAB key press and do something rather than have the TAB move focus to another control on the form. I'm handling the KeyDown event in my usercontrol, but it doesn't fire when the TAB key is pressed.

Upvotes: 1

Views: 2302

Answers (1)

BFree
BFree

Reputation: 103770

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData != Keys.Tab)
            {
              return base.ProcessDialogKey(keyData);
            }
            return false;
        }

Upvotes: 3

Related Questions