views:

64

answers:

3

I have in a panel a GDI drawing with some objects.

When the user clicks on one object, this object should be selected, if doubleClicks on it, a new pop-up (properties) window should open.

Now, I overrided
OnMouseClick => obj.Selected = Not obj.Selected
OnMouseDoubleClick => (New Properties(obj)).ShowDialog()

The problem is that when the pop-up opens (because of DoubleClick), the object became selected (because of the Click). Is there away to avoid (ignore) this intermediate Click?

(Say, in the real project I don't use click but even MouseDown, however, the question remain the same)

+1  A: 

When you get the click event, you can (using a timer or any other delay mechanism) delay the select action by slightly longer than specified by SystemInformation.DoubleClickTime. If another MouseDown event happens within that time period it is a double-click, so then you should cancel the queued select action.

Fredrik Mörk
+1 Was just about to post the same thing.
TheCloudlessSky
do you think that the selection delay will be "observed" by user?
serhio
from other part, as I noted, I already use MouseDown... Should I use DoEvents or something similar in order to obtain the second MouseDown?
serhio
@serhio: I am not sure whether the user will notice or not, that depends a bit on the user's settings I guess. Personally I find it a bit odd that the object should not be selected in the double-click case, but then I know nothing about the application in question.
Fredrik Mörk
@Frederik: Figure out a complex shape with multiple component shapes. When you click on a component the component(only) is selected. When you double click on a component, the shape properties are displayed in a window. So the DoubleClick has as result the whole shape properties window, but not the DoubleClicked component selection.
serhio
+1  A: 

What about leaving the MouseClick event handler as it is and just add another obj.Selected = Not obj.Selected to the DoubleClick event handler? That of course results in a select unselect sequence (or other way around) for the double click and I don't know if the blinking will be recognized by the user but I guess it's worth a try and it's much easier without the timer.

edit: This rather pragmatic solution doesn't work if there is any event handler attached to the SelectionChanged event of the target object because it would trigger twice where it shouldn't trigger at all.

Roland Sommer
+1  A: 

How about using the Clicks property of MouseEventArgs?

Vulcan Eager
I use it in .net 4, but it seems that is valid for .net 2 as well..
serhio