Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double-click spawns both Click and DblClick events

Status
Not open for further replies.

kmccabe64

Programmer
Aug 14, 2001
2
US
Am using VB6 svc pack 3. I have a picture control. I want a single click to perform one function and a double click to do something else.

Problem: Double click generates a single Click event immediately followed by a DblClick event

Test:
1. Create Picture1_Click event with debug.print "Single"
2. Create Picture1_DblClick event with debug.print "Double"
3. Run and double click the picture box
4. immediate window shows Single followed by Double

This looks like a bug. Anyone know a work around? Thanks.

Kevin in San Antonio
 
I didnt think it was possible, why not try using left and right button click instead of single/double left click

Private Sub Picture1_MouseUp( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
If Button = 1 Then 'Left mouse click
'code here
End If

If Button = 2 Then 'Right mouse click
'code here
End If

End Sub
 
Hi Kevin,

I am afraid this is how it works! A double click is like a single click + something. If you want to do something completely different, then follow LPlates's suggestion and capture the right click instead of a double click.

regards,
nicsin

 
It's not a bug. All controls behave this way.
They are not mind readers and do not know if you will be clicking twicw, and a single click event should fire immediately after the mouse up has happened.

There is a work-a-round in identifying what is desired, but I don't recommend it.
It means you need a delay for the length of the double click max speed, which of course meands that during this delay, the single click code should not execute, even if only a single click is made.
 
maybe you need to do something along the lines of..

yourcontrol_click()
clicked=1 (sets a predefined global integer variable to 1 to mean that you initated a single click)
timer1.interval=500 (set the delay to a suitable double click wait period - anything under 1000 (1s) will be almost unnoticeable)
timer1.enabled=true (enable a timer to wait and see if there is a second click)
end sub

timer1_timer()
if clicked=1 then (if the dblclick event was not called then run the single click code)
--> single click code
endif
timer1.enabled=false (turn the timer off now because either way it has done it's job)
end sub

yourcontrol_dblclick()
clicked=0 (Sets the single click variable to 0 so the timer does not run the single click code)
--> double click code
end sub


Hope this is of some help to you, i know it's not an ideal solution but i believe it will work.
 
Yep, that's how you would do it, except you will need to query the system as I already mentioned in order to get the actual double-click speed, to prevent the single click code from the timer from happening more than once.
>anything under 1000 (1s) will be almost unnoticeable
Not quit. It depends on the double-click speed set the the control panel. If the timer interval is set too less, and the double-click speed is set too slow, you will get a single click result from the timer.
Therefore, the timer interval should be based on the double-click speed.
 
This is true, here is the key that needs to be queried. I put 500 on my example as it is the windows default speed as far as i know.

HKEY_CURRENT_USER\Control Panel\Mouse
DoubleClickSpeed = "500" (milliseconds)

Querying the registry in VB isn't much fun though, but you can find sample code to do it here: You won't need most of it, only the parts about querying the registry.

Marc
 
Thanks, guys. This discussion has given me exactly what I needed. Marc, I grabbed the registry query code from the link you posted and incorporated it into the routines you provided and VOILA!

LPLATES, the right mouse button was not an option for me. But you got me looking at the MouseUp event.

CCLINT, thanks for your input as well and keeping Marc honest! As for the mindreader's comment, I thought that events were determined by the OS (based on dblclick rate settings) and just handed to the application. In the case of double-clicking it makes sense that a single click would precede a double-click, I just expected that once the double-click was determined that it would "eat" the singleclick at the OS level and only pass the doubleclick as an event to my program.

The test case I provided was for my understanding of the event processing. My real problem was that I needed every click on the picture to change the image (in a cyclical fashion). I was using the click event. If I clicked too rapidly, I wouldn't get all the clicks, (some were consumed as part of a dblclick). So I thought I would have the click event do something and a dbl_click event would call the single_click twice. Too naive of me. It was then that I discovered that the double-clicking caused both events to fire giving me triple-clicking results!!

Now thanks to you guys, I see how I can really recognize a true single-click and a double-click. For my own purposes, however, a MouseUp was really all I needed as it grabbed every click without all the side-effects.

But I am all the smarter now and I got registry code as a bonus! Keep up the good work.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top