When the code below is executed if sometimes it performs a "TAB" sometimes does nothing and sometimes gets my PC hung so I have to do CTR-ALT-DEL & Cancel which moves the execution of the program to the next line ("End IF"). Any idea what is missing to make it work? No special settings for mtComboBx

Private Sub myComboBx_KeyPress(ByVal sender As Object, ByVal e As     
   System.Windows.Forms.KeyPressEventArgs) Handles batch_typeComboBx.KeyPress
        If e.KeyChar = Chr(13) Then
            System.Windows.Forms.SendKeys.Send(Chr(9))
        End If
    End Sub

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
            SendKeys.Send("{TAB}")
        Else
            If e.KeyCode = Keys.Enter Then
                SendKeys.Send("{TAB}")
        End If
End If

Edited 3 Years Ago by pyTony: fixed formating

I got the error 'KeyCode' is not a member of the System.Windows.Forms.KeyPressEventArgs.

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

    If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
                SendKeys.Send("{TAB}")
            Else
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("{TAB}")
            End If
    End If

Edited 3 Years Ago by diafol: fixed formatting

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

End Sub

Thank you for your efforts. Now it works both ways, with KeyCode and with KeyChar. It may have been setting Focus in 'Validating' event for the control that caused the malfunction.

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

End Sub

This question has already been answered. Start a new discussion instead.