I am writing a simple .NET Forms application that has a hidden window and shows a system tray icon (notifyIcon) that has a context menu. When I right click it brings up the context menu but then the menu will not disappear until I select something on the list. I want to make the context menu disappear if the user clicks on anything outside of the context menu (like another window or the taskbar or start menu or another system tray icon). What is the quickest path to doing this?
So you can recreate the problem, I am attaching the function I use to handle the MouseDown event on the notifyIcon.
The problem is that I dont know what event (or events) to catch to trigger hiding the context menu.
Thanks in advance for your insight.
private void notifyIcon1_MouseDown_Test(object sender, MouseEventArgs e)
if (e.Button != MouseButtons.Right)
//clear context menu
//set context menu items to the items
ToolStripItem newContextMenuItem = contextMenuStrip1.Items.Add("Example Item");
newContextMenuItem.Image = m_ContextMenuImages["started"];
newContextMenuItem.Click += new EventHandler(ContextMenuSite_Click);