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.
Why do you need that complication at all? WinForms does it for you automatically. You just need to set the correct tab order.
go to the properties of text box and assign correct order of tabindex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With