I'm looking for what will allow the user to be able to use the Enter key to exit a TextBox control.
Printable View
I'm looking for what will allow the user to be able to use the Enter key to exit a TextBox control.
Hey,
Depending on the situation, you could set the AcceptButton property of the form to be the button that you want to click when the user hit's enter. i.e. the save button. That way when the user hits enter, that code is called.
Without some more information on what exactly you are trying to achieve, it is difficult to advise further.
Hope that helps!!
Gary
Well, you can always simply catch the enter key in the keydown event handler and move the focus to whatever other control you want.
how do you mean exit a textbox? they enter into it, type some stuff and after pressing enter, focus goes elsewhere?
i'd catch the enter key event:
Code:Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
'Do whatever, focus on next textbox, run a new method etc
End If
End Sub
maybe something like this
Code:Private Sub TextBox1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown, TextBox2.KeyDown
If e.KeyCode = Keys.Enter Then
SelectNextControl(DirectCast(sender, TextBox), True, True, False, True)
End If
End Sub