对于Button如何创建自定义双击事件 [英] How to create a custom double-click event for a Button

查看:135
本文介绍了对于Button如何创建自定义双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#在.NET Framework开发。我已经有按钮,发生在点击的事件。我也想有双点击查看同一按钮的事件。

我如何创建按钮双击事件?我想这一点,但它不工作:

  this.SetStyle(ControlStyles.StandardDoubleClick,真);
this.button1.DoubleClick + =新System.EventHandler(button1_DoubleClick);私人无效button1_DoubleClick(对象发件人,EventArgs的发送)
{
    的MessageBox.show(你是在Button.DoubleClick事件。);
}


解决方案

按钮控制(假设你在一个WinForms应用程序是)不支持双击作为本机事件。您需要也许从框架提供的按钮继承来创建自己的控制,和射击你的的DoubleClick 事件之前有关时间内听两次点击。

I'm developing in C# on the .NET Framework. I already have an event on Button which happens on one click. I also want to have an event on Double Click for the same Button.

How do I create Double click event on Button? I tried with this, but it doesn't work:

this.SetStyle(ControlStyles.StandardDoubleClick, true);
this.button1.DoubleClick += new System.EventHandler(button1_DoubleClick);

private void button1_DoubleClick(object sender, EventArgs e)
{            
    MessageBox.Show("You are in the Button.DoubleClick event.");
}

解决方案

The Button control (assuming you're in a winforms app) does not support double click as a native event. You would need to create your own control, perhaps by inheriting from the framework provided button, and listen for two clicks within the relevant time, before firing your DoubleClick event.

这篇关于对于Button如何创建自定义双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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