I have a WinForms app that starts up in the tray only. On clicking it, it opens a form. This works fine.
notifyIcon.Click += notifyIcon_Click;
//Fires on icon click, AND on contextmenuitem click
private void notifyIcon_Click(object sender, EventArgs e)
{
new ActiveIssues(_hubProxy).Show();
}
I have added a context menu, but when I click the ContextMenuItem, it first fires the NotifyIcon click event, THEN the ContextMenuItem click event, opening both forms.
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();
}
Any idea how to either NOT have it fire the notifiyicon click event or to tell that the click was on the context menu?
sender
to see what got clicked. – user1228