Tabular by pressing the Enter key in c #

If you are in this post it is very likely that your users are more accustomed to tabulate or change the photo pressing ENTER instead of TAB, it is for this reason that in this opportunity we bring you a simple and effective way to do this.

For this example we will create a simple form with 4 textbox and a button.

foco1

Then we will look for the TabIndex property and change it according to the order in which we want our focus changes to occur.

foco2
foco3
foco4
foco5
foco6

Now that we have our indices of change of focus ready. We select all the elements to which we wish to establish the focus with ENTER and create an event by double clicking on KeyUp

foco7
foco8

The following code will appear

foco9

We change the name to one that we understand. (OPTIONAL)

foco10

Finally we add the following code:

private void CambiarFoco_KeyUp(object sender, KeyEventArgs e)
{
   if (e.KeyCode == Keys.Enter)
   {
       this.SelectNextControl((Control)sender, true, true, true, true);
   }
}

Important! The fact that we can now tab with ENTER does not mean that the TAB did not work. This example allows both to work.

regards

También te podría gustar...

Deja una respuesta

Tu dirección de correo electrónico no será publicada.