Introduction
This article makes it easy to work with accounting applications and applications that need to fill their textboxes with numbers to change the focus to the enter key. This act increases the speed of users because enter key is behind the number keys and use of tab key is more difficult.
This work will be done with the following simple sentences.
It's enough to write the code in keyPressed
event:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter )
{
e.Handled = true;
Control control = GetNextControl((Control)sender, true);
if (control!= null && control.CanFocus)
control.Focus();
}
}
This component helps you to not write repeated and boring codes.
Using the Code
Add FocusProvider
to the toolbox, then drag and drop. Now if you click on each TextBoxBase
or ComboBox
, you will be able to set their EnterPressed
properties with suitable values.
It seems that it is unfavorable, but if there are many textboxes, it will be more suitable.
Thanks to
Homa for translating this article.