473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 3477
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.MenuItems.Clear();

// Show items in the list box
for (int nCount = 0; nCount < Comports.Count; nCount++)
{
Sax.Communications.SerialOptions Options = new
Sax.Communications.SerialOptions(SerConn.Options);
Options.PortName = Comports[nCount];
// Set the options
SerConn.SetOptions(Options);
if ((m_CommunicationManager.SerialConnected)
&& (m_CommunicationManager.SerialPortName == Comports[nCount]))
{
// add menu item saying this is the connected port
str = string.Format("{0} (Open)", (string)Comports[nCount]);
lstPorts.Items.Add(str);

//Create new menu item
item = new MenuItem(str);
item.Checked = true;
item.Click += new EventHandler(cmdConnect_Click);
//Add item to the submenu
mnuOpenPort.MenuItems.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)Comports[nCount]);
}
catch(System.IO.IOException)
{
str = string.Format("{0} (Not available)", (string)Comports[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(cmdConnect_Click);
mnuOpenPort.MenuItems.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.Show() 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*************@individual.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
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...
1
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...
0
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...
1
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...
0
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...
0
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...
8
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...
2
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...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.