我想到了如下方法,即创建一个Timer控件(以下名为timer_singleclick),一旦单击发生,就自动启动Timer的Tick事件(timer_singleclick_Tick(object sender, EventArgs e)),一定时间后,若没有第二次点击发生,则执行单击事件(Operate_DoubleClick()),若在这段时间有双击事件(notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e))发生,则停止Timer,此时单击事件就不会发生了。。
具体实现代码见下:
复制代码 代码如下:
int click = 1;
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) //双击托盘弹出
{
timer_singleclick.Enabled = false;
Operate_DoubleClick();
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) //单击托盘弹出
{
if (e.Button == MouseButtons.Left) timer_singleclick.Enabled = true;
}
private void timer_singleclick_Tick(object sender, EventArgs e)
{
click = click + 1;
if (click == 5)
{
Operate_Click();
timer_singleclick.Enabled = false;
click = 1;
}
}
private void Operate_DoubleClick()
{
//这里为双击的操作代码
}
private void Operate_Click()
{
//这里为单击的操作代码
}