要讓NotifyIcon響應鼠標事件,可以通過以下步驟實現:
NotifyIcon notifyIcon = new NotifyIcon();
notifyIcon.Icon = new Icon("icon.ico");
notifyIcon.Visible = true;
notifyIcon.MouseClick += new MouseEventHandler(NotifyIcon_MouseClick);
private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// 處理左鍵點擊事件
}
else if (e.Button == MouseButtons.Right)
{
// 處理右鍵點擊事件
}
}
notifyIcon.Visible = false;
notifyIcon.Dispose();
通過以上步驟,就可以實現NotifyIcon控件對鼠標事件的響應。