How to program Up Arrow Key?

  • Thread starter Thread starter chrysan
  • Start date Start date
C

chrysan

I have few textboxes on the form.

i want to program the Up Arrow and Down Arrow keys that:

When i press Up Arrow key on the textbox, the cursor will
be moved to the previous textbox, and when i press Down
Arrow key on the textbox, the cursor will be moved to the
next textbox.

Thanks.
 
* "chrysan said:
i want to program the Up Arrow and Down Arrow keys that:

When i press Up Arrow key on the textbox, the cursor will
be moved to the previous textbox, and when i press Down
Arrow key on the textbox, the cursor will be moved to the
next textbox.

Why use non-standard behavior? The user can use Tab and Shift+Tab to
move between the controls.
 
You can try to do this in the textbox.KeyDown event. Put the textboxes on
the form one after the other so their tab orders will be consecutive. Then
try a handler of this nature.

private void textBox_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
Console.WriteLine("KeyDown");
if(e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{
bool forward = e.KeyCode == Keys.Down;
e.Handled = true;
this.SelectNextControl(sender as Control, forward, true,
false, true);
}
}
=================

Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top