C# 有没有左键双击事件和右键单击事件
来源:百度知道 编辑:UC知道 时间:2024/05/21 12:51:45
我的是VS2005
有双击
右键单击的话,在Click事件中判断
if(e.Button == Button.Right)应该是这样
//右键
private void btn2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
MessageBox.Show("右键");
}
}
//双击
Button实际上是有DoubliClick事件的,只是没有出现在事件列表中而且确实没用。
自己继承下Button,实现这个也不麻烦
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 < Syst