本文介绍了如何在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?

推荐答案


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

09-25 23:33