Results 1 to 38 of 38

Thread: Trapping Enter key in VB 2005

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    31

    Trapping Enter key in VB 2005

    Hi all,

    I am trying to trap the Enter key in my form. My form contains a textbox and many buttons. The enter key will click whatever button was last selected by default.

    I tried to use:

    Code:
     Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If e.KeyCode = Keys.Enter Then
                btnEqual.PerformClick()
                MsgBox("You've pressed the Enter key")
            End If
    End Sub
    but it does not work. When i tried MyBase.KeyUp instead, it does catch it, and process the 2 statements, but only AFTER it has already processed the default keydown (button perform click) on whatever was selected.

    I have done quite a bit of searching, and still can't figure it out. Any help would be appreciated!
    Last edited by GODzillaSDM; Apr 30th, 2007 at 04:08 PM.

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