c# 托盘双击不触发单击事件的实现方法
程序员文章站
2022-07-22 10:01:45
我想到了如下方法,即创建一个timer控件(以下名为timer_singleclick),一旦单击发生,就自动启动timer的tick事件(timer_singleclic...
我想到了如下方法,即创建一个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()
{
//这里为单击的操作代码
}
具体实现代码见下:
复制代码 代码如下:
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()
{
//这里为单击的操作代码
}
下一篇: Python3.5运算符操作实例详解