我有一个WinForms应用程序,它只在托盘中启动。单击它时,它会打开一个表单。这可以很好地工作。
notifyIcon.Click += notifyIcon_Click;
//Fires on icon click, AND on contextmenuitem click
private void notifyIcon_Click(object sender, EventArgs e)
{
new ActiveIssues(_hubProxy).Show();
}我已经添加了一个上下文菜单,但是当我单击ContextMenuItem时,它首先触发NotifyIcon单击事件,然后触发ContextMenuItem单击事件,从而打开这两个窗体。
notifyIcon.ContextMenu = GetCrestContextMenu();
private ContextMenu GetCrestContextMenu()
{
var contextMenu = new ContextMenu();
contextMenu.Name = "CResT Alerts";
contextMenu.MenuItems.Add(GetTextOptionMenuItem());
return contextMenu;
}
private MenuItem GetTextOptionMenuItem()
{
var textOptionMenuItem = new MenuItem { Text = _textOptedIn ? "Opt Out of Text Alerts" : "Opt In to Text Alerts" };
textOptionMenuItem.Click += TextOptionMenuItem_Click;
return textOptionMenuItem;
}
//Fires on menuitem click, after the NotifyIcon click event is called
private void TextOptionMenuItem_Click(object sender, EventArgs e)
{
if (_textOptedIn) new TextOptOut().Show();
else new TextOptIn().Show();
}你知道如何不让它触发通知图标点击事件,或者告诉它点击在上下文菜单上吗?
发布于 2017-07-27 04:45:58
事实证明,右键单击直到上下文菜单被单击之后才会注册,因此是右键单击注册并引发了NotifyIcon单击事件。因此,我必须将为单击提供的EventArgs转换为MouseEventArgs,并选中该按钮。
private void notifyIcon_Click(object sender, EventArgs e)
{
if(((MouseEventArgs)e).Button == MouseButtons.Left) new ActiveIssues(_hubProxy).Show();
}https://stackoverflow.com/questions/45336951
复制相似问题