惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
博客园 - 聂微东
罗磊的独立博客
W
WeLiveSecurity
博客园_首页
Scott Helme
Scott Helme
V
Visual Studio Blog
T
The Exploit Database - CXSecurity.com
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
Latest news
Latest news
L
Lohrmann on Cybersecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
About on SuperTechFans
F
Full Disclosure
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 司徒正美
博客园 - Franky
C
CXSECURITY Database RSS Feed - CXSecurity.com
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
阮一峰的网络日志
阮一峰的网络日志
S
Schneier on Security
雷峰网
雷峰网
博客园 - 【当耐特】
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
T
Tor Project blog
V
V2EX
爱范儿
爱范儿
C
Check Point Blog
T
Threatpost
Project Zero
Project Zero
量子位
V
Vulnerabilities – Threatpost
Know Your Adversary
Know Your Adversary
I
Intezer
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 随风逝去(叶进)

MySQL分表(Partition)学习研究报告 用WPF+MongoDB开发房产信息收集器(4)——房产信息采集器总体介绍附程序下载 用WPF+MongoDB开发房产信息收集器(3)——MongoDB入门 用WPF+MongoDB开发房产信息收集器(2)——后台线程 用WPF+MongoDB开发房产信息收集器(1) 解决FireFox不能Debug Silverlight程序的问题 - 随风逝去(叶进) - 博客园 终于可以继续往下了! 回首2008 另类的二级域名实现方法 【更新 2008.10.16】触发C#Button的双击事件 到底要不要去面试? 【C#食谱】【面食】菜单7:用默认值初始化泛型变量 类和对象 【C#食谱】【杭帮菜】菜单2:写一个TCP客户端 C#Winform下用正则表达式限制TextBox只能输入数字 【C#食谱】【杭帮菜】菜单1:写一个TCP服务端 【C#食谱】【川菜】菜单1:列出被引用的程序集 实现需求工程的成功方法 实现需求工程的成功方法——难度:高;影响:低
触发C#Button的双击事件
随风逝去(叶进) · 2008-10-13 · via 博客园 - 随风逝去(叶进)

在C#中,Button是有DoubleClick事件的,只是它没有出现在事件列表中,而且.net也是把这个事件给"屏蔽"掉了,无论你双击一个按钮怎么快,也不会触发这个事件。

为了能够触发Button的双击事件,我们可以重载MouseDown事件,记录每次鼠标按下的时间,如果两次点击的时间足够近的话,就触发一次双击方法。

这样也大致能够达到双击的效果,我所采用的方法其实和这个类似,是继承Button类,重载Button类的Click事件,在Click事件中判断两次点击的时间,如果近的话,就触发双击事件。废话少说,上代码:


//======================================================================
//
//        Copyright (C) 2007-2008 杭州石鼓文信息科技有限公司    
//        All rights reserved
//
//        filename :ButtonEx
//        description :
//
//        created by 叶进 at  10/13/2008 15:38:24
//        http://adaiye.cnblogs.com
//
//======================================================================

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;public class ButtonEx : Button
    {
        
public new event EventHandler DoubleClick;

        DateTime clickTime;

bool isClicked = false;protected override void OnClick(EventArgs e)
        {
            
base.OnClick(e);if (isClicked)
            {
                TimeSpan span 
= DateTime.Now - clickTime;
                
if (span.Milliseconds < SystemInformation.DoubleClickTime)
                {
                    DoubleClick(
this, e);
                    isClicked 
= false;
                }
            }
            
else
            {
                isClicked 
= true;
                clickTime 
= DateTime.Now;
            }
        }
    }

这样,就可以为创建的ButtonEx按钮添加DoubleClick事件了:

button.DoubleClick += new EventHandler(Button_DoubleClick);  // 双击按钮事件