我想到了如下方法,即建立一個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()
{
//這裡為單擊的作業碼
}