Triggering the enter button to do an action

mhrappstead

Newcomer
Joined
Nov 30, 2006
Messages
4
I am currently in a college coarse and need help with a problem. I am trying to make it so that when (physically) press enter while being in a text it will create a msgbox(""). I have everything working except for the fact that I can't find a way to make enter become a trigger for an action. Please help
 
What have you tried? Are you handling the KeyDown event of the textbox? This seems to do the trick for me with both a multi-line and single-line textbox:
Visual Basic:
Private Sub textbox2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox2.KeyDown
    If (e.KeyCode = Keys.Enter) Then
        MessageBox.Show(textbox2.Text)
    End If
End Sub
 
Back
Top