gpt4 book ai didi

c# - 系统托盘图标双击/单击问题

转载 作者:行者123 更新时间:2023-11-30 22:06:42 25 4
gpt4 key购买 nike

我创建了系统托盘图标并添加了两次单击事件双击、单击。我尝试了鼠标点击和正常点击。

    SysTray.MouseClick += new MouseEventHandler(SysTray_MouseClick);
SysTray.MouseDoubleClick += new MouseEventHandler(SysTray_MouseDoubleClick);

void SysTray_MouseClick(object sender, MouseEventArgs e)
{
SingleClick = true;

if (e.Button == MouseButtons.Left)
{
System.Threading.Thread.Sleep(300);
if (SingleClick)
{
//To Do
}
}
}

void SysTray_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SingleClick = false;
System.Threading.Thread.Sleep(20);
//To Do
}
}

如果我双击系统托盘图标,它将自动执行单击图标。

如何解决双击/单击问题

最佳答案

我知道这已经有一段时间了,但我只是使用计时器解决了这个问题:

Timer singleClickTimer = new Timer();

private void trayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Give the double-click a chance to cancel this
singleClickTimer.Interval = (int) (SystemInformation.DoubleClickTime * 1.1);
singleClickTimer.Start();
}
}

private void singleClickTimer_Tick(object sender, EventArgs e)
{
singleClickTimer.Stop();

// do single click here
}

private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Cancel the single click
singleClickTimer.Stop();

// do double click here
}
}

关于c# - 系统托盘图标双击/单击问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23457600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com