开发者

Way to differentiate Click from DoubleClick

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)


How about using the Clicks property of MouseEventArgs?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜