开发者

Ignore Single Click in WPF

I have a user control wherein I would like to do something different in the case of a single click vs. double click. I'm handling mouseLeftButtonDown event as such:

 private void cueCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        switch (e.ClickCount)
        {
            case 1:
                {
                    cueCanvas.Focus();
                    e.Handled = true;
                    _mouseStartPoint = Mouse.GetPosition(null);
                    break;
                }
            case 2:
                {
                    double pos = Mouse.GetPosition(cueCanvas).X;
                    TimeSpan time = ConvertFromPosition(pos);
                    AddNewEvent(time);
                    e.Handled = true;
                    break;
   开发者_运维技巧             }
        }
    }

The problem is that WPF doesn't really care how many times you've clicked the mouse so I get the first click event even though I'm about to get a second one (in the case of a double-click). Has anyone come up with a way to work around this? I realize I could try to get clever and set some timers such that the first click gets "canceled" in the event that the second one comes in (I realize this is what the framework would be doing anyway). If that's the only answer, does anyone know how we query the system for the appropriate click delay?


To my knowledge, there's really no way to do this. The problem is that you're fighting reality. :-) In reality, there are 2 clicks to a double-click. You want single click to be ignored if quickly followed by a double-click.

You'll have wait a short interval to see if it's followed by a second click. You can query for that interval using the SystemInformation class from WinForms, or just call the Win32 API directly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜