Valerie Meunier

Valerie Meunier

  • 1.5k
  • 693
  • 57.6k

how to cancel tab key in KetPress windows forms?

Aug 2 2022 11:09 AM


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.

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

Answers (3)