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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click vs Double Click timing 1

Status
Not open for further replies.

gmmastros

Programmer
Feb 15, 2005
14,900
0
36
US
I've created a user control that is causing me some problems.

If you start a new VB project and put a standard picture box, image box, text box, etc.... on the form, and then put debug.print statements in the click and DblClick event handlers, it appears as though the click event always fires first, followed closely by the double click event.

Ex:

Code:
Option Explicit

Private Sub Picture1_Click()
    
    Debug.Print "click: " & Timer
    
End Sub

Private Sub Picture1_DblClick()
    
    Debug.Print "double click: " & Timer
    
End Sub

The problem I have with my User Control is that the double click event fires before the click event fires. I have a fair amount of code getting executed in both events, but I don't think it should matter how much code there is, the order of events (in my opinion) should be set in stone.

Is there some way to modify the behavior?

Is there a fixed order in which the click & double click events SHOULD fire? Should the click event always occur before the double click event?



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
It's not easy finding information related to click and double clicks. Try googling it someday. [smile]

Anyway, I found this:


For those objects that receive Mouse events, the events occur in this order: MouseDown, MouseUp, Click, DblClick, and MouseUp.

Of course, this does not explain why I get different behavior in my user control (that is based on a picture box).

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
YES! Freaky.

If I start a new vb6 project with a single picture box and this code:

Code:
Option Explicit

Private Sub Picture1_Click()
    Debug.Print "Click"
End Sub

Private Sub Picture1_DblClick()
    Debug.Print "Double Click"
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Debug.Print "Mouse Down"
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Debug.Print "Mouse Up"
End Sub

After running the project and double clicking in the picture box, I get...
[tt][blue]
Mouse Down
Mouse Up
Click
Double Click
Mouse Up
[/blue][/tt]

Similar code run in my application, I get:

[tt][blue]
Mouse Down
Mouse Up
Double Click
Mouse Up
Click
[/blue][/tt]

Notice that the click event occurs last. I can't explain why.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
How is your control built? Is it a composite control or owner drawn? Are you raising any events of your own or mapping any events to the user control's events? I am just wondering if we are seeing the click event from one thing and the double click event from something else. Just a thought.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
[blue]How is your control built? Is it a composite control or owner drawn? [/blue]

It's a composite control. Primarily, there is a picture box which is the basis for my user control. There are other (standard) controls built my user control.

[blue]Are you raising any events of your own or mapping any events to the user control's events? [/blue]

Both. My user control raises events not found with standard controls, but it also re-raises many of the standard events. Certain functionality should be "trapped" by the control and handled internally. Yet, each event that I am capturing must also be sent (with a RaiseEvent) to the form with the control on it. For example, in my usercontrol I have...

Code:
Private Sub picUserControlPictureBox_Click()

    Debug.Print "Click"

    RaiseEvent Click
    
End Sub

Private Sub picUserControlPictureBox_DblClick()

    Debug.Print "Double Click"

    If CursorMode.GetCursorMode = vbCursorModeNormal Then
        RaiseEvent DblClick
    Else
        CursorMode.DoubleClickAction
    End If

End Sub

[blue]I am just wondering if we are seeing the click event from one thing and the double click event from something else. Just a thought. [/blue]

I have my application AND the user control loaded in to the same instance of the VB6 IDE. I'm not ready to rule anything out, but it appears as though I am capturing the correct events.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 

If your events ALWAYS fire in the wrong order, for 'kicks and giggles' I would try switching BLUE and RED code around:
Code:
Option Explicit

Private Sub Picture1[blue]_Click()[/blue]
    Debug.Print "click: " & Timer
End Sub

Private Sub Picture1[red]_DblClick()[/red]
    Debug.Print "double click: " & Timer
End Sub
to get:
Code:
Option Explicit

Private Sub Picture1[red]_DblClick()[/red]
    Debug.Print "used to be click: " & Timer
End Sub

Private Sub Picture1[blue]_Click()[/blue]
    Debug.Print "used to be double click: " & Timer
End Sub
And see what will happen....

Have fun.

---- Andy
 
Andy, That doesn't work. Sometimes I want just a single click.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Andy!

I like "kicks and giggles" just as much as anyone else. I had actually done as you suggested. Then, I quickly realized that it wouldn't work, so I changed it back. Oddly enough, this seems to have fixed the problem I had with the events firing out of order. I can't explain it, and it bothers me a bit, but what's a lonely programmer to do?

By the way, your post got me to thinking about the procedure attributes. I had poked around in there a bit, but didn't change anything.

Thanks.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Just so I have things straight, you having problems with the click/dblclick events on the container side with the picture box?

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
yes.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I see you got it straightened out. Maybe not explained, but at least functional. :)

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Just to add some fodder to this discussion...
msdn said:
Click Event (ActiveX Controls)


Occurs when the user presses and then releases a mouse button over an object. It can also occur when the value of a control is changed.

For a Form object, this event occurs when the user clicks either a blank area or a disabled control. For a control, this event occurs when the user:

Clicks a control with the left or right mouse button. With a CheckBox, CommandButton, Listbox, or OptionButton control, the Click event occurs only when the user clicks the left mouse button.


Selects an item in a ComboBox or ListBox control, either by pressing the arrow keys or by clicking the mouse button.


Presses the SPACEBAR when a CommandButton, OptionButton, or CheckBox control has thefocus.


Presses ENTER when a form has a CommandButton control with its Default property set to True.


Presses ESC when a form has a Cancel button — a CommandButton control with its Cancel property set to True.


Presses anaccess key for a control. For example, if the caption of a CommandButton control is "&Go", pressing ALT+G triggers the event.
You can also trigger the Click event in code by:

Setting a CommandButton control's Value property to True.


Setting an OptionButton control's Value property to True.


Changing a CheckBox control's Value property setting.
Syntax

Private Sub Form_Click( )

Private Sub object_Click([index As Integer])

The Click event syntax has these parts:

Part Description
object Anobject expression that evaluates to an object in the Applies To list.
index An integer that uniquely identifies a control if it's in acontrol array.


Remarks

Typically, you attach a Click event procedure to a CommandButton control, Menu object, or PictureBox control to carry out commands and command-like actions. For the other applicable controls, use this event to trigger actions in response to a change in the control.

You can use a control's Value property to test the state of the control from code. Clicking a control generates MouseDown and MouseUp events in addition to the Click event. The order in which these three events occur varies from control to control. For example, for ListBox and CommandButton controls, the events occur in this order: MouseDown, Click, MouseUp. But for FileListBox, Label, or PictureBox controls, the events occur in this order: MouseDown, MouseUp, and Click. When you're attaching event procedures for these related events, be sure that their actions don't conflict. If the order of events is important in your application, test the control to determine the event order.

Note To distinguish between the left, right, and middle mouse buttons, use the MouseDown and MouseUp events.

If there is code in the Click event, the DlbClick event will never trigger, because the Click event is the first event to trigger between the two. As a result, the mouse click is intercepted by the Click event, so the DblClick event doesn't occur.


Good Luck

 
For what it's worth , I did read the help file.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 

WOW!
Talking about real 'shot in the dark' on my part :)

The important part is - it works now. You just have to create some convoluted explanation/reason WHY... :)

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top