Private Sub FrmForm1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' Tastenbehandlung auf Formularebene (Bedingung: Me.KeyPreview = True)
If e.KeyCode = Keys.Enter AndAlso Not (e.Shift OrElse e.Control OrElse e.Alt) _
AndAlso TypeOf Me.ActiveControl Is TextBox Then
' Mit ENTER zum nächsten Control springen, aber nur, wenn es eine Textbox ist
Dim myBox As TextBox = CType(Me.ActiveControl, TextBox)
If Not myBox.Multiline Then
' Aber doch nicht, wenn es eine Multiline-Textbox ist
Me.ActiveControl = Me.GetNextControl(Me.ActiveControl, True)
e.Handled = True
End If
ElseIf e.KeyCode = Keys.Enter AndAlso e.Shift AndAlso Not (e.Control OrElse e.Alt) _
AndAlso TypeOf Me.ActiveControl Is TextBox _
AndAlso TypeOf Me.GetNextControl(Me.ActiveControl, False) Is TextBox Then
' Mit Shift+ENTER zum vorherigen Control springen,
' aber nur, wenn es eine Textbox ist
' und wenn das vorherige Element auch eine Textbox ist
Me.ActiveControl = Me.GetNextControl(Me.ActiveControl, False)
e.Handled = True
End If
End Sub