I have a textbox and in some cases in Enter event I need to set the focus to a different textbox.
I tried that code:
private void TextBox1_Enter(object
Postpone executing the Focus() method until after the event is finished executing. Elegantly done by using the Control.BeginInvoke() method. Like this:
private void textBox2_Enter(object sender, EventArgs e) {
this.BeginInvoke((MethodInvoker)delegate { textBox3.Focus(); });
}
textBox.Select();
or
textBox.Focus();
or
set TabIndex = 0
from properties of that textBox
.
both methods are use to set focus on textBox
in C#, .NET
You could handle the KeyPress event instead:
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
TextBox2.Focus();
}
}