Using Enter Key to move to Another control in a Form

Daudi

New member
Joined
Aug 25, 2006
Messages
4
Location
Kenya
Programming Experience
Beginner
Plaese assist me the code that I will use to move from one control to another with enter key as the case in VB 6 using KeyAscii.
 
i think u can use 'tab' key 4 moving from one control to another in vb.net(priority can b set by "tab index property")...if this nt wat ur meant pls forgive me..
 
one way you could do it, if you specificly want to use the enter key is have an event on each textbox's onKeyDown event that checks if the key is the enter key, and then selects the next control in the tab order:

VB.NET:
    Private Sub txtFirst_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFirst.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtSecond.Focus()
        End If
    End Sub
 
If you want this for every control on your form, it can all be done in one function .
if you want to make "Enter" jump to the control with the next tabindex, you can replace the Enter with a TAB.

Just put this function in your form:

VB.NET:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
'Replace Enter by TAB
     If keyData = Keys.Enter Then
        SendKeys.Send("{Tab}")
        Return True
     End If
End Function
 
Last edited:
Back
Top