P
Peter Steele
I have a form with four text fields, each with sequentially ordered
tabstops. I want to have the fields recognize the return key and
automatically shift the focus to the next control. I created the following
event handler that I've assigned to the KeyUp event of each of the TextBox
controls:
private void Any_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
else if (e.KeyCode == Keys.Return)
{
foreach (Control c in this.Controls)
if (c.Focused) this.GetNextControl(c, true).Focus();
}
}
This works when the current control is the first text field, moving the
focus correctly to the second text field. However, when I hit enter in the
second text field, the focus moves to the fourth text field, skipping over
the third? What am I doing wrong here?
tabstops. I want to have the fields recognize the return key and
automatically shift the focus to the next control. I created the following
event handler that I've assigned to the KeyUp event of each of the TextBox
controls:
private void Any_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
else if (e.KeyCode == Keys.Return)
{
foreach (Control c in this.Controls)
if (c.Focused) this.GetNextControl(c, true).Focus();
}
}
This works when the current control is the first text field, moving the
focus correctly to the second text field. However, when I hit enter in the
second text field, the focus moves to the fourth text field, skipping over
the third? What am I doing wrong here?