如何在MouseDown路由事件中使用e.ClickCount来区分单击和双击? [英] How can I use e.ClickCount in MouseDown Routed Event to distinguish click and doubleclick?

查看:173
本文介绍了如何在MouseDown路由事件中使用e.ClickCount来区分单击和双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MSDN中搜索了e.ClickCount,它提供了以下示例:

I searched MSDN for e.ClickCount, and it provieds the following eg.:

<textblock x:name="tb" text="" background="Black" foreground="White" />


以及后面的代码:


and the code behind:

public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

           this.tb.MouseDown += new MouseButtonEventHandler(tb_MouseDown);
        }

       void tb_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Checks the number of clicks.
           if (e.ClickCount == 1)
            {
                // Single Click occurred.
                this.tb.Text = "Single Click";

               DoSomethingForClick();

           }
            if (e.ClickCount == 2)
            {
                // Double Click occurred.
                this.tb.Text += "Double Click";

              DoAnotherForDoubleClick();

            }
            if (e.ClickCount >= 3)
            {
                // Triple Click occurred.
                this.tb.Text += "Triple Click";
            }

       }
    }



但是我想要得到的是这样的:

(1)一次单击一次,然后执行DoSomethingForClick().没问题!

(2)一次单击两次时,仅执行DoAnotherForDoubleClick().不首先执行DoSomethingForClick(),然后像在MSDN中那样执行DoAnotherForDoubleClick(),因为tb_MouseDown被触发了2次.

我该怎么办?



But what I want to get is like this:

(1)When I click once at one time, then execute DoSomethingForClick(). This has no problem!

(2)When I click twice at one time, then only execute DoAnotherForDoubleClick(). NOT firstly execute DoSomethingForClick() and then execute DoAnotherForDoubleClick() like in the MSDN eg., because tb_MouseDown fired 2 times;

How can I do?

推荐答案

我认为您的问题是由系统为每次双击"发送以下消息流引起的(请选中"WM_LBUTTONDBLCLK" "(在msdn上).

WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK-替换了第二个WM_LBUTTONDOWN
WM_LBUTTONUP
I think your problem is caused by the system sending the following stream of messages for each ''double click'' (check ''WM_LBUTTONDBLCLK'' on msdn).

WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK -- Second WM_LBUTTONDOWN replaced
WM_LBUTTONUP


这篇关于如何在MouseDown路由事件中使用e.ClickCount来区分单击和双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆