I just recently began in C# development, and I was working on a forms-based project and I am trying to perform a “tab” action when the user is on a form and pressed the Enter key.
I know the answer is probably quite simple, but I am a newbie in this realm.
Welcome to SO Tex,
I believe there are two methods to accomplish this, would just involve adding:
Option 1: Grabbing the Next Control if an Enter KeyPress was performed
In the properties of your form, set the KeyPreview property of the form to
true.The code below will capture your “Enter-Press” event and perform the logic that you are looking for:
This actually allows for the user to press “Shift+Enter” to go to the proceeding tab as well.
Option 2: Using the SendKeys method
I am not sure if this method is still commonly used or may be considered a “hack”? I would recommend the first one, but I believe both should work for your needs.