的WinForms如何调用一个按钮双击事件? [英] WinForms how to call a Double-Click Event on a Button?

查看:108
本文介绍了的WinForms如何调用一个按钮双击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是让被点击一次按钮,当事件发生,我想只有当按钮双击事件发生。可悲的是双击事件不会出现在IDE事件列表。

Rather than making an event occur when a button is clicked once, I would like the event to occur only when the button is double-clicked. Sadly the double-click event doesn't appear in the list of Events in the IDE.

任何人都知道一个很好的解决这个问题?谢谢!

Anyone know a good solution to this problem? Thank you!

推荐答案

没有标准按钮没有反应到双击。请参阅文件<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.button.doubleclick.aspx\">Button.DoubleClick事件。它不以双击作出反应,因为在Windows按钮总是反应点击和永不双击。

No the standard button does not react to double clicks. See the documentation for the Button.DoubleClick event. It doesn't react to double clicks because in Windows buttons always react to clicks and never to double clicks.

你恨你的用户?因为你将创建一个按钮,作用比系统中的任何其他按键不同,有些用户将永远不会明白这一点。

Do you hate your users? Because you'll be creating a button that acts differently than any other button in the system and some users will never figure that out.

这是说你要创建按钮衍生事件给这个独立的控制(因为<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx\">SetStyle是被保护的方法)

That said you have to create a separate control derived from Button to event to this (because SetStyle is a protected method)

public class DoubleClickButton : Button
{
    public DoubleClickButton()
    {
        SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true);
    }
}

然后,你必须在你的code hanlder手动添加的DoubleClick 事件,因为它仍然不会在IDE中显示:

Then you'll have to add the DoubleClick event hanlder manually in your code since it still won't show up in the IDE:

public partial class Form1 : Form {
    public Form1()  {
        InitializeComponent();
        doubleClickButton1.DoubleClick += new EventHandler(doubleClickButton1_DoubleClick);
    }

    void doubleClickButton1_DoubleClick(object sender, EventArgs e)  {
    }
}

这篇关于的WinForms如何调用一个按钮双击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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