Click to See Complete Forum and Search --> : How do I check for the Enter key in a textbox?
RealNickyDude
Jan 21st, 2003, 03:35 PM
:confused:
Pirate
Jan 21st, 2003, 03:57 PM
you mean if it's pressed in the textbox ??
RealNickyDude
Jan 21st, 2003, 04:01 PM
yeah, it's basically a follow on from the all of the sudden... thread, you type something into a textbox, press return and I want to capture that so I can do something.
Pirate
Jan 21st, 2003, 04:02 PM
you seem so busy
if that what you mean then check this :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar()) = 13 Then
MsgBox("You Pressed Enter Key")
' put your code here
End If
End Sub
:D
Pirate
Jan 21st, 2003, 04:05 PM
two posts at the same time :D
RealNickyDude
Jan 21st, 2003, 04:09 PM
I get a blue squiggle under e.KeyChar and it tells me that 'KeyChar' is not a member of 'System.EventArgs'. Does something need declaring?
Pirate
Jan 21st, 2003, 04:11 PM
that code should go under the KeyPress EVENT .
RealNickyDude
Jan 21st, 2003, 04:17 PM
Yeah, your right. When I double-clicked on the textbox to get the code, it gave me this:
Private Sub txtUserInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUserInput.TextChanged
End Suband I assumed that would be ok. But what do I know, pah :rolleyes:
Pirate
Jan 21st, 2003, 04:23 PM
in the code editor click the first code on the top left "Class Name" scroll down and select your textbox then on the right combobox scroll down to KeyPress event , click it , write your code there .Done !;)
RealNickyDude
Jan 21st, 2003, 04:29 PM
THANK YOU!!!! I wondered how to change the arguments of various controls and it never occured to me to change the class name from the top left pull down, doh!!
:D :D :D :D :D :D :D
Pirate
Jan 21st, 2003, 04:31 PM
:cool: :D ;)
RealNickyDude
Jan 21st, 2003, 04:38 PM
...and I call myself a VB programmer! :eek: :p
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.