A
A
Andrey Smirnov2019-03-12 22:28:51
C++ / C#
Andrey Smirnov, 2019-03-12 22:28:51

How to catch TAB press in C# WinForms?

Hello!
How can I make C# WinForms so that when focus is on a TextBox and TAB is pressed, a tab is inserted?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Arxont, 2019-03-13
@GameDev_Easy

1 option

textBox2.Multiline = true;
textBox2.AcceptsTab = true;

Option 2, keep track of PreviewKeyDown
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
   if (e.KeyCode == Keys.Tab)
   {
      textBox1.AppendText("\t");
      e.IsInputKey = true;
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question