Results 1 to 10 of 10

Thread: [RESOLVED] [HELP] E keys?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    USA
    Posts
    237

    Resolved [RESOLVED] [HELP] E keys?

    I think its called e.keys?

    How do I make a function so when you press a key like "F2"
    I can make it do another function like bring up a message box?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [HELP] E keys?

    The 'e' is the second parameter of the relevant event handler, which would likely be for your form's KeyDown event. You would then test the e.KeyCode or e.KeyData property, depending on exactly what behaviour you want with respect to modifier keys, against your target value. If they match then you perform your action. The target value will be a single or composite value from the Keys enumeration, e.g. Keys.F2.

    Note that, if you have controls on your form that process keyboard input, e.g. TextBoxes, and you want your form to trap this key(s) no matter what control has focus, you must set the form's KeyPreview to True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    USA
    Posts
    237

    Re: [HELP] E keys?

    I just want it so when you press F2 it will pop open a message box...

  4. #4
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: [HELP] E keys?

    Although already stated....
    Step 1 Set the forms keyPreview to true
    Step 2 Create a sub on the form to handle the keydown event
    Step 3 in the Sub you created in step 2 check if e.KeyCode = Keys.F2 and if so call MessageBox.Show("F2 pressed")
    Have you tried Google?

  5. #5
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: [HELP] E keys?

    Specifying 7777's thing.
    vb Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    2.         If e.KeyCode = Keys.F2 Then
    3.             MessageBox.Show("Example.")
    4.         End If
    5.     End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    USA
    Posts
    237

    Re: [HELP] E keys?

    Do I have to like, Declare something? It gives me an error.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [HELP] E keys?

    Quote Originally Posted by VBFiEND View Post
    Do I have to like, Declare something? It gives me an error.
    Perhaps you could help us out a bit and tell us what the error message is. If you want us to help you then please don't make us guess what the problem is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    USA
    Posts
    237

    Re: [HELP] E keys?


  9. #9
    Member
    Join Date
    Jun 2009
    Posts
    53

    Re: [HELP] E keys?

    are you using VB 2005, 2008 or 2010 and not vb6? make sure to not put that code in a sub but right below the "Public Class ..." line

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Location
    USA
    Posts
    237

    Re: [HELP] E keys?

    Oh ok, I was putting it in the wrong class, Thank you, Works great. +rep to all.

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