Menuitem of notificationIcon only works on the second click.

G

Gerard Buskermolen

Hello,

I've created a C# console application.
When the application starts, I show in NotificationIcon with a related
contextmenu. This contextmenu has 3 menuitems.
Each menuitem opens a window using (for example)

menuItem.Click += new EventHandler(ChangePassword_Click);

The ChangePassword_Click method opens a window (allowing the user to
change his password).

When I right-click the notification icon, the contextmenu appears.

So far, so good.

But.... when I select one of the menuitem, nothing happens.
Right-clicking the notification icon again, does not show the
contextmenu again, but instead immediately opens the change-password
window (or one of the other 2 windows if I selected that menuitem).

I found out that the problem is NOT that the change-password window is
hidden or does not have the focus or someting like that, but that the
ChangePassword_Click method is called on the second right-click on the
icon instead of immediately when I select the menuItem.

Does anyone recognize this problem?

Thank for any reaction.
 
D

Dave

I've never seen this problem but I have a few questions about the design that may help you:

1. Are you manually showing the context menu, or is the NotifyIcon.ContextMenu property set?
2. Just in case, are you sure your binding to the "Click" event of the MenuItem and not the NotifyIcon itself?
3. Can you verify that no other events are being handled that may affect the expected behavior?

Hope it helps
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Hello,

I've created a C# console application.
A console app?
You need to create a win app to have access to all the win. app processing
manily the message pump.
Does anyone recognize this problem?

No really, some code will help though.


In any case this is a piece of code I use with no problem at all:
//*************************************************************
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;



this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();

this.contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] {this.menuItem1});


this.menuItem1.Index = 0;
this.menuItem1.Text = "E&xit";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

notifyIcon1.ContextMenu = this.contextMenu1;

//*************************************************************


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top