|
-
Jun 8th, 2000, 09:01 AM
#1
Thread Starter
Hyperactive Member
Hello All,
Here is the solution to a problem I had earlier involving function keys.
Problem: How do you make a function key call a sub, like Private Sub cmdSearch_Click(), while another control has focus.
Solution: You have to set the forms keypreview property to true. You can do this at design time or during runtime with code ex - frmMain.KeyPreview = True
From there it is a simple issue of the select case statement. Here is the reference from the MSD-Library.
KeyPreview Property Example
This example creates a form keyboard handler in the KeyDown event. Each of the first four function keys displays a different message. To try this example, paste the code into the Declarations section of a form, and then press F5. Once the program is running, press any one of the first four (F1 – F4) function keys.
Private Sub Form_Load ()
KeyPreview = True
End Sub
Private Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1: MsgBox "F1 is your friend."
Case vbKeyF2: MsgBox "F2 could copy text."
Case vbKeyF3: MsgBox "F3 could paste text."
Case vbKeyF4: MsgBox "F4 could format text."
End Select
End Sub
Sal
P.S. - Thanks to Megatron & Kedman for their leads to a resolution to this problem. This is a great forum.
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
|