473,756 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem adding menuitem to context menu attached to NotifyIcon

Sorry Ive added this twice (sortof) but if I'd added an addendum to the
first one then this would probably have been ignored.

This problem affects a ContextMenu attached to a NotifyIcon object. I don't
get the problem with context menus attached to list boxes etc.
Ive also seen a noticeable slow down in speed when the menu attempts to hide
after the problem occurs.

When I build a dynamic submenu on the first time round, it shows a nice list
of items.
When it gets run through on a 2nd pass, an indicator shows presence of a sub
menu but the menu never pops up.

Is this a recognized bug?

Claire
Nov 16 '05 #1
4 3507
paste your code
Nov 16 '05 #2
Hi Jack,

The way Ive managed to solve the problem is by disposing of the parent menu
item then recreating it before adding the subitems.
Old code
========

/// Adds a submenu item for each available serial port showing current
status
private void TestComports()
{
MenuItem item;
string str;
int idx = 0;
// Clear old sub menu
mnuOpenPort.Men uItems.Clear();

// Show items in the list box
for (int nCount = 0; nCount < Comports.Count; nCount++)
{
Sax.Communicati ons.SerialOptio ns Options = new
Sax.Communicati ons.SerialOptio ns(SerConn.Opti ons);
Options.PortNam e = Comports[nCount];
// Set the options
SerConn.SetOpti ons(Options);
if ((m_Communicati onManager.Seria lConnected)
&& (m_Communicatio nManager.Serial PortName == Comports[nCount]))
{
// add menu item saying this is the connected port
str = string.Format(" {0} (Open)", (string)Comport s[nCount]);
lstPorts.Items. Add(str);

//Create new menu item
item = new MenuItem(str);
item.Checked = true;
item.Click += new EventHandler(cm dConnect_Click) ;
//Add item to the submenu
mnuOpenPort.Men uItems.Add(item );
}
else
{
str = "";
// Test ports will open. If they open OK then close them again
try
{
SerConn.Open();
str = string.Format(" {0} (Closed)", (string)Comport s[nCount]);
}
catch(System.IO .IOException)
{
str = string.Format(" {0} (Not available)", (string)Comport s[nCount]);
}
finally
{
try
{
if (SerConn.IsOpen )SerConn.Close( );
}
catch
{
}
}
// Add new item to submenu
lstPorts.Items. Add(str);
item = new MenuItem(str);
item.Click += new EventHandler(cm dConnect_Click) ;
mnuOpenPort.Men uItems.Add(item );
}
}
}

Nov 16 '05 #3
Remove the menuitem from the context menu.
Add child Menu items to it.
Re add the menuitem to the contextmenu.

This usually happens on controls where the contextmenu has been called by
the contextMenu.Sho w() method, but it looks like it also happens on
NotifyIcon.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Claire" <cc@hotmai1.com > wrote in message
news:38******** *****@individua l.net...
Sorry Ive added this twice (sortof) but if I'd added an addendum to the
first one then this would probably have been ignored.

This problem affects a ContextMenu attached to a NotifyIcon object. I
don't get the problem with context menus attached to list boxes etc.
Ive also seen a noticeable slow down in speed when the menu attempts to
hide after the problem occurs.

When I build a dynamic submenu on the first time round, it shows a nice
list of items.
When it gets run through on a 2nd pass, an indicator shows presence of a
sub menu but the menu never pops up.

Is this a recognized bug?

Claire

Nov 16 '05 #4
thanks Mick
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1358
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of items dynamically added}) All the code works #1 when only the MdiParent form is used, as soon as i open an MdiChild in it, right after the popup event returns, i get this error: ...
1
2040
by: Brian Martel | last post by:
I am trying to create a dynamic flyout submenu off of a contextmenu. I can right click and get the base contextmenu ok. On the Popup event I add MenuItem's to the collection of one of the items so it has a flyout submenu when selected. If I try and add more than 1 item to the submenu it only shows up the first time. This same code works fine if it is part of a MainMenu but not with a ContextMenu. Has anyone seen this before? Have you...
0
1388
by: Claire | last post by:
When I run the following code through on the first round, my sub-menu (branched off mnuOpenPorts menuitem) shows a nice list of ports. When it gets run through on the 2nd pass, the sub menu indicates that it should be there but there's no items appearing in it. (ie a small indicator arrow is there showing there should be a sub menu but nothing pops up) When I step through the code, I have 5 items in Comports. After adding all the sub menu...
1
2247
by: Joe | last post by:
I have a MenuItem which is was added to the context menu at design time. The context menu is for a button on a toolbar. At runtime I add and remove sub-menuitems to and from this menu item. The problem is the dynamically added items don't always appear. If I add say 3 menu items and click to see the menu, the sub menu appears and shows 3 items. This is fine. Now, if I add another item and click to see the submenu, nothing displays. The...
0
1598
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
0
1340
by: ZH | last post by:
Hi There, I have an application that runs from the systray. When the user right clicks on the icon it shows the user a list of of menu items. That works without a problem. The problem is that the only event I've been able to fire for a MenuItem is the CLICK event. I 've been unable to get the or Popup events to fire. I've tried adding handlers for the and Popup events, but that didn't work. I've also tried using menuitems as...
8
5268
by: Dave | last post by:
I am trying to write an event-driven application with no main window that runs "forever". It waits on a named event and then displays a window depending on data pased in a memory-mapped file. I started with a standard console application and it all works fine, except that it does not terminate tidily when the user logs off/shuts down. So, I figured I needed a message loop to pick up WM_QUIT. I studied the code in "Waiting in a message loop"...
2
2166
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu objects). It is possible (and it's my case) that these 2 MainMenu objects use some different MenuItem objects and some identical MenuItem objects. For example, let's assume that: mainMenu1 contains miFile, miEdit, miHelp mainMenu2 contains miFile,...
2
2083
by: stillcoding | last post by:
Hi I have a problem with memory usage increasing when I right click to display the context menu on a notifyIcon OS: Windows XP Professional SP2 Software: VS2005 Professional edition SP1 The steps to recreate my problem are as follows: Start a new c# windows application
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.