Results 1 to 12 of 12

Thread: How do I check for the Enter key in a textbox?

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Question How do I check for the Enter key in a textbox?

    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    you mean if it's pressed in the textbox ??

  3. #3

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    you seem so busy
    if that what you mean then check this :
    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As _
    2.     System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    3.  
    4.    If Asc(e.KeyChar()) = 13 Then
    5.      MsgBox("You Pressed Enter Key")
    6.   ' put your code here
    7.    End If
    8.  End Sub

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    two posts at the same time

  6. #6

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    that code should go under the KeyPress EVENT .

  8. #8

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Yeah, your right. When I double-clicked on the textbox to get the code, it gave me this:

    VB Code:
    1. Private Sub txtUserInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUserInput.TextChanged
    2.  
    3.     End Sub
    and I assumed that would be ok. But what do I know, pah
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 !

  10. #10

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    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!!

    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

  12. #12

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    ...and I call myself a VB programmer!
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width