Valerie Meunier

Valerie Meunier

  • 954
  • 693
  • 72.5k

how to cancel tab key in KetPress windows forms?

Aug 2 2022 11:09 AM

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)