Controls


How to program the Enter Key to Act as a Tab in a VB.Net Form

Set KeyPreview property of Form to True in the Properties window.


Private Sub Form1_KeyPress(ByVal sender As Object, _
                                            ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                                            Handles MyBase.KeyPress
     If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
          System.Windows.Forms.SendKeys.Send("{TAB}")
     End If
End Sub

' This works too
Protected Overrides Sub onkeypress(ByVal e As KeyPressEventArgs)
     If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
          System.Windows.Forms.SendKeys.Send("{TAB}")
     End If
End Sub