4

我正在.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.");
}
4

1 回答 1

3

Button控件(假设您在 winforms 应用程序中)不支持将双击作为本机事件。您可能需要通过从框架提供的按钮继承来创建自己的控件,并在触发DoubleClick事件之前在相关时间内侦听两次单击。

于 2010-12-09T11:32:22.540 回答