Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NotifyIcon and ContextMenu Bug ??

NotifyIcon and ContextMenu Bug ??

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2sky
    wrote on last edited by
    #1

    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:

    N 1 Reply Last reply
    0
    • 2 2sky

      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:

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      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.

      L 2 2 Replies Last reply
      0
      • N Nish Nishant

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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 :(

        1 Reply Last reply
        0
        • N Nish Nishant

          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.

          2 Offline
          2 Offline
          2sky
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups