3
Answers

how to cancel tab key in KetPress windows forms?

Hi,

How to cancel the tab key in the event textbox1_KeyPress or textbox1_KeyDown in windows forms? When pressing the tab key in textbox1, i want the focus remaining on textbox1.
I tried this but it doesn't work: textbox1 loses the focus.

Thanks
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
            {
                ActiveControl = textBox1;
                return;
            }

Answers (3)