Coverting the Enter Key to a Tab in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to intercept the enter key and convert it to a tab character in C#.
It was very simple to do in VB6, however, I have not found any references in
..NET. People I work with expect to use "Enter" rather than "Tab".
 
To intercept the key for the specified control, you can do the following.

Use in the form's class:
private void control_KeyPress(object sender, KeyPressEventArgs e)
{

if (e.KeyChar == (Char)13)
{
nextcontrol.Focus();
e.Handled = true;
}

}

And add the handler to the designer code:
this.control.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.control_KeyPress);

Replace "control" with the name of the control, "nextcontrol" to the name of
the next control.

You can also use the Form Designer to generate the shell code.
 
Back
Top