Assigning a context menu to a NotifyIcon control, it automatically right-clicks and opens the assigned context menu. If you want to execute some logic before the context menu is actually displayed, assign a delegate to the contextMenu.Popup event.
... contextMenu.Popup += new EventHandler(contextMenu_Popup); ... private void trayIcon_IconClicked(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) {
My guess about why the window appears is that the context menu that you open uses NotifyIcon as the target control, so when you click on it, it starts the click handler assigned by NotifyIcon.
Edit: Another option is to use ContextMenuStrip. NotifyIcon also has a ContextMenuStrip property, and it seems to have much more functionality associated with it (noticed that I could do more, programmable wise). You might want to do this if something is not working for some reason.
source share