tags:

views:

30

answers:

2

I have written a login. Now I want to do this (press return to login):

Private Sub login_KeyDown(ByVal sender As Object, 
               ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    If e.KeyData = Keys.Return Then
        login()
    End If
End Sub

It does not work. At this time it works only with a button.

+1  A: 

Try using the KeyDown events of the textboxes instead.

Protected WithEvents txtUsername As TextBox
Protected WithEvents txtPassword As TextBox

Private Sub Login_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUsername.KeyDown, txtPassword.KeyDown
    If e.KeyData = Keys.Return Then login()
End Sub
Yes,Thanks!It works
vb.net
A: 

Or you could just set the AcceptButton property of your form to be the button you would like to be "pressed" when return/enter is pressed. This is exactly what this feature is here for.

Matt