[RESOLVED] UserControl Events Problem
I have a User control with a label on it. If I raise a user control click event from the label it works fine. If I raise a user control dblclick event from the label it works fine. If I raise both user control events from their respective label events, then I only receive the click event. If I fire off a msgbox from the user control click event and another from the dblclick event then when I double click the label at runtime I get the msgbox for the click event and a quick flash of the msgbox indicating that a second click event was raised.
I assume this is a timing issue, and I have attempted (albeit unsuccessfully) to implement a click count routine in conjunction with a timer control, but even if it had worked it seems like a cludge anyway.
So for the sake of learning, hypothetically what if I needed the ability to have MouseUp, MouseDown, Click and Doubleclick events? Even my Mouse up and mousedown events are superseded by the click event.
Any help would be appreciated.
Re: UserControl Events Problem
Welcome to the Forums! :wave:
Good question :)
You need to determine the Doubleclick speed with the GetDoubleClickTime API. Then, you need to set a Timer's Interval to that time. You also need to create a Boolean variable and set it to True on Double Click, and False in Click. You then, need to use the Timer's Timer event to do whatever.
Here is the code :
Code:
Private Declare Function GetDoubleClickTime Lib "user32.dll" () As Long
Private Declare Function SetDoubleClickTime Lib "user32.dll" (ByVal wCount As Long) As Long
Private MouseDBlClicked As Boolean
Private Sub Form_Load()
Timer1.Interval = GetDoubleClickTime
End Sub
Private Sub Label1_Click()
Timer1.Enabled = True
MouseDBlClicked = False
End Sub
Private Sub Label1_DblClick()
MouseDBlClicked = True
End Sub
Private Sub Timer1_Timer()
If MouseDBlClicked Then
MsgBox "double clicked"
Timer1.Enabled = False
Else
MsgBox "clicked"
Timer1.Enabled = False
End If
End Sub
I'm attaching a small sample with
I hope it helps :)
Re: UserControl Events Problem
Thanks for the warm welcome and the fantastic response. The code worked beautifully. There is a slight delay in the event response but IT WORKS, and the delay is a small trade-off for having the ability to utilize both events. Thanks a Million!!!!
Re: UserControl Events Problem
You're welcome, and good work :thumb:
Yeah, the delay is actually caused by the GetDoubleClickTime API. Believe it or not, that is actually the time Windows uses to respond to / determine a Double click event. I'm just glad it worked for you :D
Keep posting on this wonderful site ;)