silverlight鼠标双击2

网友做的一个双击的例子

原理是
第一次点击 开一个线程(sheep 200 且 lock)
如果在200ms内再点击 线程继续sheep 200  统计点击次数
...........
............
timeout 后
线程执行  比较传入的要求点击数与统计点击的次数
true 的话就执行

 

 public class MClick
    {
        public static void MulClick(int count, MouseButtonEventHandler handle, object sender, MouseButtonEventArgs e)
        {
            bolClicking = true;
            if (bolClicked)
            {
                intClickCount++;
            }
            else
            {
                bolClicked = true;
                intCount = count;
                handleClick = handle;
                objSender = sender;
                mbeE = e;
                asyncOperation = AsyncOperationManager.CreateOperation(null);
                objThreadLock = new object();
                Thread thread = new Thread(ResetThread);
                thread.Start();
                while (!thread.IsAlive) ;
            }
        }


        private static int intTimeOut = 200;
        public static int TimeOut
        {
            get
            {
                return intTimeOut;
            }

            set
            {
                intTimeOut = value < 1 ? 1 : value;
            }
        }

        private static int intCount;
        private static object objSender;
        private static MouseButtonEventArgs mbeE;
        private static MouseButtonEventHandler handleClick;
        private static int intClickCount = 0;
        private static bool bolClicked = false;
        private static bool bolClicking = false;
        private static object objThreadLock;
        private static AsyncOperation asyncOperation;

        private static void ResetThread()
        {
            while (bolClicking)
            {
                bolClicking = false;
                Thread.Sleep(TimeOut);
            }

            lock(objThreadLock)
            {
                if (intCount == ++intClickCount)
                {
                    asyncOperation.Post(callback, objSender);  
                }

                intClickCount = 0;
                bolClicked = false;
            }

        }

        private static void callback(object state)
        {
            handleClick(objSender, mbeE);
        }
    }


============================
只是测试性,满乱的~~哈哈。有兴趣的朋友可以改进~
改成
MulClick(点击次数, 控件, 函数)

使用
==============================
        public Page()
        {
            InitializeComponent();
            LayoutRoot.MouseLeftButtonUp += new MouseButtonEventHandler(HandleClick);
        }

        private void HandleClick(object sender, MouseButtonEventArgs e)
        {
           
            //MClick.MulClick(1, onClick, sender, e);

            MClick.MulClick(2, onDoubleClick, sender, e);

        }

        private void onClick(object sender, MouseButtonEventArgs e)
        {
            txtMsg.Text = "单击";
        }

        private void onDoubleClick(object sender, MouseButtonEventArgs e)
        {
            txtMsg.Text = "双击";
        }
    }

转载于:https://www.cnblogs.com/wmt1708/archive/2009/02/11/1388349.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值