How to detect tab key pressing in C#?

Posted by user342325 on Stack Overflow See other posts from Stack Overflow or by user342325
Published on 2010-06-02T03:58:20Z Indexed on 2010/06/02 4:03 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

I want to detect when tab key is pressed in a textBox and focus the next textbox in the panel. I have tried out keyPressed method and keyDown method. But when I run the program and debug those methods are not calling when the tab key is pressed. Here is my code.

private void textBoxName_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Tab)

        {

            textBoxUsername.Focus();
        }
    }

private void textBoxName_KeyPress(object sender, KeyPressEventArgs e)

{

        if (e.KeyChar==(char)Keys.Tab)

        {
            textBoxUsername.Focus();
        }
    }

Please correct me.Thank you.

© Stack Overflow or respective owner

Related posts about c#

Related posts about key