Paul Chan
May 20th, 1999, 08:38 PM
Hi! Everybody!
In my application, there is one Form that will capture the key pressed. I will check the key if it is F1 then i will show a bitmap on my Form. Actually, i want the bitmap to be displayed as the F1 key is continuouly pressed without releasing and the bitmap will not be displayed as the key is released. Then i try to use the KeyDown and KeyUp event but if i continue to press the F1 key the bitmap will be displayed and the bitmap is still on the screen even the key is released. Is there any method to achieve such an operation?
Thank you anybody help!
Ravi Kiran
May 25th, 1999, 03:50 AM
Hi,
Did I get you right? You want:
1. Show bitmap on F1-key press.
2. remove bitmap on F1-key release
3. Keep showing, as long as F1 is pressed.
Right?
You should catch the keyDown and kepUp events and check. You are saying, it doesnt work!. Surprises me!!. May be the catch is in: How you are showing the bitmap?
Try this sample: Take a new form. Put a image control (Image1) on it. From Properties window, change its picture property to the picture of interest (browse & select the one you want to show on F1). Set its visibility to False.
Copy & paste the following code and run. Press F1 and test.
private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
If KeyCode = vbKeyF1 then
Image1.Visible = true
' You can use either of the lines to get the same effect.
' to test, comment the above line and uncomment the me.picture line below.
' Do the same in Keyup also
'me.Picture = Image1.Picture
End If
End Sub
private Sub Form_KeyUp(KeyCode as Integer, Shift as Integer)
If KeyCode = vbKeyF1 then
Image1.Visible = false
' You can use either of the lines to get the same effect.
' to test, comment the above line and uncomment the line below.
' Do the same in keydown also
'me.Picture = nothing
End If
End Sub
private Sub Form_Load()
KeyPreview = true
' I checked with the above line (un)commented.
' The effect is same. It always disappears when F1 is released.
End Sub
I tested it and it had the desired effect.
Now add more controls to the form and check.
Preferably add some edit controls, set the cursor into then and then press F1. For edit controls case KeyPreview in Formload should be "On".
If the result is not satisfactory, please mail me.
I would be interested to look into.
Ravi Kiran