NotifyIcon and ContextMenu Bug ??
-
When I associate a ContextMenu with a NotifyIcon, the MenuItems' Popup event doesn't fire, can anyone tell me if this is a bug inside the framework or am I doing something wrong ? I'm quite confused here... :confused:
See if this article helps. Else post some code snippets. http://www.codeproject.com/csharp/trayiconmenu01.asp Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
See if this article helps. Else post some code snippets. http://www.codeproject.com/csharp/trayiconmenu01.asp Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
This article does't cover this I think Nish... Too bad I can't attach a file to this post. But if you want to try it, or anyone else, just create a blank C# project, create a notifyicon, create a contextmenu with a child menuitem that has a childmenuitem on it's own. Now attach a popup event to the first menuitem (the one that contains a child). If you now attach this context menu to the form, this popup event fires, but if you attach it to the notifyicon, the event doesn't fire at all :(
-
See if this article helps. Else post some code snippets. http://www.codeproject.com/csharp/trayiconmenu01.asp Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
If you make sure the trayicons' "Icon" property is set to a valid icon, you should be able to copy-paste the code below in an empty C# project: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace NotifyMenu { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.NotifyIcon TrayIcon; private System.Windows.Forms.ContextMenu MnuContext; private System.Windows.Forms.MenuItem MnuItem1; private System.Windows.Forms.MenuItem MnuItem2; private System.ComponentModel.IContainer components; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.TrayIcon = new System.Windows.Forms.NotifyIcon(this.components); this.MnuContext = new System.Windows.Forms.ContextMenu(); this.MnuItem1 = new System.Windows.Forms.MenuItem(); this.MnuItem2 = new System.Windows.Forms.MenuItem(); // // TrayIcon // this.TrayIcon.ContextMenu = this.MnuContext; this.TrayIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("TrayIcon.Icon"))); this.TrayIcon.Text = "NotifyMenu Tray"; this.TrayIcon.Visible = true; // // MnuContext // this.MnuContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MnuItem1}); // // MnuItem1 // this.MnuItem1.Index = 0; this.MnuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.MnuItem2}); this.MnuItem1.Text = "Item 1"; this.MnuItem1.Popup += new System.EventHandler(this.MnuItem1_Popup); // // MnuItem2 // this.MnuItem2.Index = 0; this.MnuItem2.Text = "Item 2"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.ContextMenu = this.MnuContext; this.Name = "Form1"; this.Text = "Form1"; } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void MnuItem1_Popup(obj