【发布时间】:2011-05-22 19:28:55
【问题描述】:
我在 .NET Framework 上使用 C# 进行开发。我已经在 Button 上有一个事件,只需单击一下即可。我还想为同一个按钮双击双击事件。
如何在 Button 上创建双击事件?我试过这个,但它不起作用:
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.");
}
【问题讨论】:
-
你是什么意思不起作用?具体错误是什么?运行时错误?编译错误?
-
当我点击按钮时... MessageBox 不显示...
-
@SpeksETC 我希望它是一个编译错误,因为该事件未在
Button类上声明... -
为了将来参考,
Control.DoubleClick事件的documentation 包含一个有用的参考表,指示各种控件如何处理(或不处理)该事件。
标签: c# winforms button double-click