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}"); } }
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.
everytime I press enter key I hear (may be error)sounds