call to button.click event when textbox.keypress = enter

ramone

Freshman
Joined
Sep 29, 2005
Messages
26
hello,
i want to call the click event handler of a button when the user hits the enter key after typing some text in a textbox, but the keypress event of the text box only works with characters keys, what can i do?

thank you
 
Code:
 Private Sub txt_peypress(ByVal system As System.Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            ' whatever needs to be done here
        End If
    End Sub
 
You probably want to set e.handled to true to prevent extra carrige returns in multiline textboxes or the error sound in singleline textboxes.
 
Back
Top