|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
keydown event of usercontrol not working
Hi friends,
I have one usercontrol in that i have keydown event. But its not being getting called. The keypreview property is set to false. i tried changing it to true but then also its not working. I want to change the backcolor of frame depending on key pressed If user has pressed "F1" then change to blue If user has pressed "F2" then change to red If user has pressed "entrer" then call some function Code:
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
If ques <= totalques Then
If KeyCode = vbKeyF1 Or KeyCode = vbKeyAdd Then
Frame2.BackColor = RGB(0, 0, 255)
Label1.Caption = "BUY"
ElseIf KeyCode = vbKeyF2 Or KeyCode = vbKeySubtract Then
Frame2.BackColor = RGB(255, 0, 0)
Label2.cpation = "SELL"
End If
If KeyCode = vbKeyReturn Or KeyCode = vbKeySeparator Then
cnfrm = MsgBox("Confirm order", vbOKCancel)
If cnfrm = vbOK Then
test1
Else
End If
End If
End If
End Sub
Please tell me how to go abt it Its very urgent Thanx in advance |
|
#2
|
||||
|
||||
|
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = 112 Then Me.BackColor = RGB(0, 0, 255) ElseIf KeyCode = 113 Then Me.BackColor = RGB(255, 0, 0) End If End Sub |
|
#3
|
||||
|
||||
|
Hi sheeba,
i changed the code to Code:
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer) MsgBox KeyCode End Sub when i press F1 it sometimes shows me msgbox two times with value of keycode as 112 and sometimes it displays help. i want everytime the keyup event to be fired. when i press F2 nothing happens Please help me its very urgent. Quote:
|
|
#4
|
|||
|
|||
|
There is some form property setting that controls if the keyup event is passed to the form keyup handler or to whatever control the mouse pointer is over. But I don't recall what it's called, look at the available form properties or refer to the vb documentation.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#5
|
|||
|
|||
|
Use a timer and the last code in the next link
http://vb-tec.de/inkey.htm |
|
#6
|
||||
|
||||
|
The proprty is KeyPreview and it should be set to true. Instead of using ActivexControl i used Simple VB project and now my code is working absolutely fine
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
While inkey$ <> ""
Wend
If ques <= totalques Then
If KeyCode = vbKeyF1 Or KeyCode = vbKeyAdd Then
KeyCode = 0
Frame2.BackColor = RGB(0, 0, 255)
Label1.Caption = "BUY"
ElseIf KeyCode = vbKeyF2 Or KeyCode = vbKeySubtract Then
KeyCode = 0
Frame2.BackColor = RGB(255, 0, 0)
Label1.Caption = "SELL"
End If
If KeyCode = vbKeyReturn Or KeyCode = vbKeySeparator Then
KeyCode = 0
cnfrm = MsgBox("Confirm order", vbOKCancel)
If cnfrm = vbOK Then
storedata "1"
Text2.SetFocus
End If
End If
End If
End Sub
Quote:
|
|
#7
|
|||
|
|||
|
Thanks for posting the solution!
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > keydown event of usercontrol not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|