How to set ENTER key as TAB in windows form in C#

 
Most of the user use Enter key except Tab to move focus in the next controls because it is very faster to press Enter key instead of Tab key. We can do this by using Sendkeys method in .net.basically Sendkeys.Send method Sends keystrokes to the active application.

Before using this code you need to set the keypreview property of windows form to True.

[VB.Net]

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs)
	If e.KeyData = System.Windows.Forms.Keys.Enter Then
		SendKeys.Send("{TAB}")
	End If
End Sub

[C#.Net]

private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == System.Windows.Forms.Keys.Enter)
            {
                SendKeys.Send("{TAB}");
            }
        }

2 thoughts on “How to set ENTER key as TAB in windows form in C#”

  1. Thanks for the code. I used it. When enter key is pressed, its focusing the next control, but the text in the textbox gets deleted. Could you please suggest a solution.

Comments are closed.