Canvas MouseDown fires before DoubleClick

Upon DoubleClick I was hoping to have a Canvas control bring up an overlaid TextBox for editing AND upon MouseDown, be able to drag it.

It seems that MouseDown always gets in first and does not pause to see if DoubleClick might fire. It seems like a Canvas can only do one of these tricks.

Any elegant work-arounds suggested …

Why would you think mousedown would not fire first?
Since a DblClick is MouseDown-Up-Down-Up? meaning both MouseDown and MouseUp will most likely fire before DBl can .

I believe also that if you put RETURN TRUE in the MOUSEDOWN, then DBL can’t/won’t fire at all as you have indicated that you (not the system) have dispatched the MouseDown event, thus terminating the rest of the sequence.

Expected behavior. For Canvas controls we tend to do our own double click handling because there are single, double and even triple clicks that need to be defined.

[quote=133785:@Ian Ramsay]Upon DoubleClick I was hoping to have a Canvas control bring up an overlaid TextBox for editing AND upon MouseDown, be able to drag it.

It seems that MouseDown always gets in first and does not pause to see if DoubleClick might fire. It seems like a Canvas can only do one of these tricks.

Any elegant work-arounds suggested …[/quote]

Use a boolean flag you set in MouseDown, like TextHere = True, then in MouseDown return immediately if TextHere is false.

Then if MouseDown occurs inside the text box carry out the drag then set TextHere back to false in MouseUp.

You must also set TextHere to false whenever you stop displaying the text box.

Have you considered using a timer to wait for the double-click?Set the timer to mode=1 in mousedown or mouseup, and if the double-click occurs, cancel the timer. If the timer fires, then execute the single-click code.

If you only want to drag, then just return true from mousedown. Handle the dragging in mousedrag and handle the doubleclick in doubleclick.

Mouse down ALWAYs occurs as it can’t ever “know” ahead of time whether it will be or won’t be a double click.
And waiting the double click time, if its set really long, would induce noticeable oddities in some circumstances that you don’t control.
A person could click, nothing would appear to happen until the double click time expired & then the mouse down would occur.
And a timer will have that exact same effect.

I should have said “then execute the click and hover code”

It really all depends on the behavior you want. For example, Finder’s behavior: Click(Mouse up)=select, shift-click=select more (on mouse down) , DoubleClick=open, then when Doubleclick expires, if the mouse hasn’t moved, rename occurs. Drag moves a file, and you’ll notice that if you drag an unselected file, the selection doesn’t change (no mouse up) but the drag still happens… iTunes has a different behavior (selection changes on mouse down), Mail has a more finder-like behavior.

You’ll notice that something like a button will give visual feedback on mouse down but the actual action occurs on mouse up. Drag changes the feedback to indicate whether the mouse up will initiate the action…

I think the best policy for what you described is just to return true in mouse down and handle the drag and double click events as needed…

OK … Many thanks for these many clever thoughts.

Shall report back from the lab soon with an answer that works (and hopefully elegantly).

Cheers … Ian

Unless the person pre-warns you that it’s going to be a double click there is nothing that can be done to make it work/elegant without waiting for the time to expire. How will the computer know “wait!!! don’t fire this one is going to be a double click?”