如何实现伪双击事件

本文介绍了如何通过检测两次单击之间的间隔时间来判断是否为双击事件,并提供了两种实现方法:第一种是利用DateTime类记录上次点击时间,通过比较两次点击时间差判断;第二种是在DevExpress的TreeList控件中,通过引入Timer控件来延迟触发单击事件的处理,确保双击事件与单击事件能被正确区分。

大体都是用两次单击的时间差来判断一下是否是双击。

SystemInformation.DoubleClickTime默认是500

第一种方式:可以参考http://blog.youkuaiyun.com/zbssoft/article/details/5602658

 

 DateTime   lastDownTime   =   DateTime.Now;   
   private    void   comboBox1_MouseDown( object   sender,   MouseEventArgs   e)   
  {   
  TimeSpan   sp   =   DateTime.Now   -   lastDownTime;   
   if   (sp.Milliseconds   <=   SystemInformation.DoubleClickTime)   
  {   
  System.Console.WriteLine( " DoubleClick ");   
  }   
   else   
  {   
  System.Console.WriteLine( " Click ");   
  }   
  lastDownTime   =   DateTime.Now;   
  }  
 

 

Derexpress中的TreeList控件触发双击事件的时候,总会触发单击事件。为了处理单击和双击的时候分别处理不同的代码,解决方案如何:

第二种方式:http://www.devexpress.com/Support/Center/p/S136873.aspx。记得是在Timer控件的Interval 属性为500

bool needHandleMouseClick =  true;
         private  void tlDokumente_MouseClick( object sender, MouseEventArgs e)  {
            timer1.Start();
        }

         private  void treeList1_MouseDoubleClick( object sender, MouseEventArgs e) {
            needHandleMouseClick =  false;
             //  perform your code here
            
// ...
            
// System.Diagnostics.Process.Start(file);
        }

         private  void timer1_Tick( object sender, EventArgs e)    {
            timer1.Stop();
             if (needHandleMouseClick)   {
                 //  your code here
                
// ...
                
//  wbDokument.Navigate(file);
            }
            needHandleMouseClick =  true;
        }

 

 

转载于:https://www.cnblogs.com/51net/archive/2012/07/02/2573378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值