So what I am trying to do is to be able to continuously type into all of 10 text boxes. I start from the first one, then after 3 characters were typed change focus to next and after 3 characters were typed focus on the next.
I have done that part, but what if there is text already in second text box? I have tries Clear() but it creates a bug for which won’t let me type more than 1 character.
So when all text boxes are filled with junk data, so when I start typing at first text box 123 then moves to second text box 456 third 789 ect. but while next field is cleared first.
I am trying to work with this:
public PingIPRange()
{
InitializeComponent();
txtF1.TextChanged += new EventHandler(NextField);
txtF2.TextChanged += new EventHandler(NextField);
txtF3.TextChanged += new EventHandler(NextField);
txtF4.TextChanged += new EventHandler(NextField);
txtT1.TextChanged += new EventHandler(NextField);
txtT2.TextChanged += new EventHandler(NextField);
txtT3.TextChanged += new EventHandler(NextField);
txtT4.TextChanged += new EventHandler(NextField);
txtInterval.TextChanged += new EventHandler(NextField);
txtRepeat.TextChanged += new EventHandler(NextField);
}
private void NextField(object sender, EventArgs e)
{
if (txtF1.TextLength == 3)
{
txtF2.Focus();
}
if (txtF2.TextLength == 3)
{
txtF3.Focus();
}
if (txtF3.TextLength == 3)
{
txtF4.Focus();
}
if (txtF4.TextLength == 3)
{
txtT1.Focus();
}
if (txtT1.TextLength == 3)
{
txtT2.Focus();
}
if (txtT2.TextLength == 3)
{
txtT3.Focus();
}
if (txtT3.TextLength == 3)
{
txtT4.Focus();
}
if (txtT4.TextLength == 3)
{
txtInterval.Focus();
}
if (txtInterval.TextLength == 3)
{
txtRepeat.Focus();
}
if (txtRepeat.TextLength == 3)
{
btnPing.Focus();
}
}
}
Add the
Enterevent for the TextBoxes, and do aSelectAllon the text.Also, your NextField method doesn’t quite do what you think it does. Make sure your controls
TabIndexvalues are in the correct order, then try changing your code to this:It will choose the next control based on the tab order of the form.