Microsoft KB Archive/814737

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

Article ID: 814737

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * 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(&quot;SubMenu2&quot;) 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(&quot;SubMenu2&quot;); menuItem1.MenuItems.Add(mnuItem); }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. Create a new Windows application by using Visual Basic 2005, Visual Basic .NET, or Visual C# .NET.

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

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

By default, ContextMenu1 is added to Form1. 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.</li> Create a submenu item for MenuItem1. To do this, type SubMenu1 in the Type Here box.</li> Click to select NotifyIcon, and then press the F4 key to open the Properties window. Set the Context Menu property to ContextMenu1.</li> 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.</li>  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(&quot;SubMenu2&quot;) MenuItem1.MenuItems.Add(mnuSubItem) Visual C# .NET Code // Add a Sub menu item MenuItem mnuItem; mnuItem = new MenuItem(&quot;SubMenu2&quot;); menuItem1.MenuItems.Add(mnuItem); </li> Save the project. On the Debug menu, click Start to run the application.</li> Right-click NotifyIcon in the notification area, and then point to MenuItem1.

SubMenu1 is displayed, but SubMenu2 is not displayed.</li></ol>

<div class="references_section">