|
-
Oct 29th, 2009, 01:35 AM
#1
Thread Starter
Addicted Member
[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?
-
Oct 29th, 2009, 01:48 AM
#2
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.
-
Oct 29th, 2009, 01:51 AM
#3
Thread Starter
Addicted Member
Re: [HELP] E keys?
I just want it so when you press F2 it will pop open a message box...
-
Oct 29th, 2009, 02:03 AM
#4
Addicted Member
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")
-
Oct 29th, 2009, 04:53 AM
#5
Hyperactive Member
Re: [HELP] E keys?
Specifying 7777's thing.
vb Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F2 Then
MessageBox.Show("Example.")
End If
End Sub
-
Oct 31st, 2009, 07:54 PM
#6
Thread Starter
Addicted Member
Re: [HELP] E keys?
Do I have to like, Declare something? It gives me an error.
-
Oct 31st, 2009, 08:20 PM
#7
Re: [HELP] E keys?
 Originally Posted by VBFiEND
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.
-
Nov 1st, 2009, 08:44 PM
#8
Thread Starter
Addicted Member
-
Nov 1st, 2009, 08:49 PM
#9
Member
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
-
Nov 1st, 2009, 09:15 PM
#10
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|