3个回答
展开全部
long lastMouseDown; //局部变量
Public Form1() //窗体的构造函数
{
this.MouseDown += (object sender, MouseEventArgs e) =>
{
if (e.Button == MouseButtons.Left) lastMouseDown = DateTime.Now.Ticks;
else lastMouseDown = 0;
};
this.MouseUp += (object sender, MouseEventArgs e) =>
{
if (e.Button == MouseButtons.Left && lastMouseDown > 0)
{
TimeSpan p = new TimeSpan(DateTime.Now.Ticks - lastMouseDown);
if (p.TotalSeconds > 3)
{
MessageBox.Show("鼠标按下了 "+p.TotalSeconds+" 秒!");
}
lastMouseDown = 0;
}
};
}
Public Form1() //窗体的构造函数
{
this.MouseDown += (object sender, MouseEventArgs e) =>
{
if (e.Button == MouseButtons.Left) lastMouseDown = DateTime.Now.Ticks;
else lastMouseDown = 0;
};
this.MouseUp += (object sender, MouseEventArgs e) =>
{
if (e.Button == MouseButtons.Left && lastMouseDown > 0)
{
TimeSpan p = new TimeSpan(DateTime.Now.Ticks - lastMouseDown);
if (p.TotalSeconds > 3)
{
MessageBox.Show("鼠标按下了 "+p.TotalSeconds+" 秒!");
}
lastMouseDown = 0;
}
};
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
_MouseDownTimer = new Timer();
_MouseDownTimer.Interval = 3000;
_MouseDownTimer.Tick += new EventHandler( OnMouseDownTimer_Tick );
}
void OnMouseDownTimer_Tick( object sender, EventArgs e )
{
_MouseDownTimer.Stop();
MessageBox.Show( "按下鼠标左键3秒。" );
}
private Timer _MouseDownTimer;
private void Form1_MouseDown( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
_MouseDownTimer.Start();
}
}
private void Form1_MouseUp( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
if ( _MouseDownTimer.Enabled ) _MouseDownTimer.Stop();
}
}
}
{
public Form1()
{
InitializeComponent();
_MouseDownTimer = new Timer();
_MouseDownTimer.Interval = 3000;
_MouseDownTimer.Tick += new EventHandler( OnMouseDownTimer_Tick );
}
void OnMouseDownTimer_Tick( object sender, EventArgs e )
{
_MouseDownTimer.Stop();
MessageBox.Show( "按下鼠标左键3秒。" );
}
private Timer _MouseDownTimer;
private void Form1_MouseDown( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
_MouseDownTimer.Start();
}
}
private void Form1_MouseUp( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
if ( _MouseDownTimer.Enabled ) _MouseDownTimer.Stop();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
放个Timer控件
当MouseDown的时候开始计时
然后么你应该会了吧
当MouseDown的时候开始计时
然后么你应该会了吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询