Using Enter to move to next text box
How to move to the next text box using enter.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sushta GuthnarPosted Jun 26, 2012, 3:00 PM
VulpesPosted Jun 15, 2012, 12:51 PM
First of all, you need to handle the KeyPress event for the first textbox by double clicking the KeyPress event in the Properties Box to open up a skeleton eventhandler and adding the following code to it:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
SendKeys.Send("{TAB}")
e.Handled = True
End If
End Sub
Now handle the KeyPress events for all the other textboxes (except the last one) by locating their KeyPress events in the Properties Box and choosing the handler for the first textbox from the drop down box. This, of course, means that all the textboxes will share the same handler.
Notice that the TAB key should still work as well as the ENTER key which is good practice IMO as this is what most Windows users are used to.