Text box to go to next tab index control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When the max length of a text box has been reached, I want the focus to go to
the next control based on tab index. How do I code or what property do I set?
 
You could do something similar to the following.

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.TextLength == this.textBox1.MaxLength)
{
this.SelectNextControl(this.textBox1, true, true, true, true);
}
}

--
Tim Wilson
..NET Compact Framework MVP

Mike L said:
When the max length of a text box has been reached, I want the focus to go to
the next control based on tab index. How do I code or what property do I
set?
 
Tim said:
You could do something similar to the following.

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.TextLength == this.textBox1.MaxLength)
{
this.SelectNextControl(this.textBox1, true, true, true, true);
}
}

I'd do it on KeyUp, because I believe TextChanged doesn't fire until the
control loses focus (i might be thinking of javascript though).

private void textBox1_KeyUp(object sender, KeyEventArgs e) {
if (textBox1.TextLength == textBox1.MaxLength) {
textBox2.Focus();
}
}

actually I just tried it and textchanged does work after every keypress.
So either TextChanged or KeyUp will work for you.
 
Back
Top