BUG: The Popup event does not raise for the menu item of the Context Menu control that is associated with the Notify icon (814737)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft .NET Framework 2.0

Beta Information

This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location where you downloaded the release.

SYMPTOMS

When you right-click the Notify icon for a Microsoft .NET application, the Context Menu control associated with the Notify icon is displayed. If you point to the menu items, the submenu items are displayed. However, the menu items Popup event does not raise before the submenu items are displayed. Therefore, the code associated with the menu items Popup event, such as adding submenu items dynamically, does not run.

WORKAROUND

To work around this bug, do one of the following things:
  • Associate the Context Menu with the Windows Form.
  • Use the Context Menu control Popup event instead of the menu items Popup event of the Context Menu control.
To use the Context Menu control Popup event to work around this bug, add the following code in the Context Menu control Popup event handler:

Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Code
     Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
           ' Add a menu item dynamically
           Dim mnuSubItem As New MenuItem("SubMenu2")
           MenuItem1.MenuItems.Add(mnuSubItem)
     End Sub
Microsoft Visual C# .NET Code
     private void contextMenu1_Popup(object sender, System.EventArgs e)
     {
          // Add a menu item dynamically
          MenuItem mnuItem;
          mnuItem = new MenuItem("SubMenu2");
          menuItem1.MenuItems.Add(mnuItem);
     }

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. Create a new Windows application by using Visual Basic 2005, Visual Basic .NET, or Visual C# .NET.

    By default Form1 is created.
  3. Drag a NotifyIcon component to Form1.

    By default, NotifyIcon1 is added to Form1.
  4. Drag a Context Menu control to Form1.

    By default, ContextMenu1 is added to Form1.
  5. Add a menu item to ContextMenu1. To do this, click to select Context Menu on the form, and then type MenuItem1 in the Type Here box.
  6. Create a submenu item for MenuItem1. To do this, type SubMenu1 in the Type Here box.
  7. Click to select NotifyIcon, and then press the F4 key to open the Properties window. Set the Context Menu property to ContextMenu1.
  8. Set the NotifyIcon1 property to any valid Icon file with an .ico extension. The Icon file is typically located in the C:\Program Files\Microsoft Visual Studio .NET\Common7\Graphics\icons folder.
  9. Add the following code to the MenuItem1_PopUp event handler:

    Visual Basic .NET or Visual Basic 2005 Code
         'Add a menu item dynamically
         Dim mnuSubItem As New MenuItem("SubMenu2")
         MenuItem1.MenuItems.Add(mnuSubItem)
    Visual C# .NET Code
         // Add a Sub menu item 
         MenuItem mnuItem;
         mnuItem = new MenuItem("SubMenu2");
         menuItem1.MenuItems.Add(mnuItem);
  10. Save the project. On the Debug menu, click Start to run the application.
  11. Right-click NotifyIcon in the notification area, and then point to MenuItem1.

    SubMenu1 is displayed, but SubMenu2 is not displayed.

REFERENCES

For additional information, visit the following Microsoft Web site:

NotifyIcon Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformsnotifyiconclasstopic.asp

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbMenu kbControl kbCtrl kbContMenu kbbug KB814737 kbAudDeveloper