How to create a NotifyIcon with 2 ContextMenuStrips - LClick and RClick

Hi,

I want to use a NotifyIcon with two ContextMenuStrips - one that works on a left mouse click, the other on a right click.

I've tried the following in a MouseClick() event:

If (e.Button = Windows.Forms.MouseButtons.Left)Then

NotifyIcon.ContextMenuStrip = MyLeftClickMenu

ElseIf (e.Button = Windows.Forms.MouseButtons.Right)Then

NotifyIcon.ContextMenuStrip = MyRightClickMenu

EndIf

But the behaviour is erratic - the menus don't show or show the wrong one.

This should be simple (I know Nortons Anti-virus uses 2 ContextMenus). If you can help, I would appreciate it.

I'm using VB.Net 2005 Beta2 on XPSp2

Thanks.

[1077 byte] By [Deskman] at [2007-12-22]
# 1

Hi Deskman,

Your basic logic is right, but after you set the ContextMenuStrip, you don't call the show method explicitly. Therefore, as you can imagine, when the left button is clicked, the context menu is flip-flopped, but it's not shown. Then, it's really hard to tell what will happen when you click the right button of the mouse.

advice: add a show() statement after the above code.



private void Do_MouseClicked(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.appNotifyIcon.ContextMenuStrip = this.leftContextMenuStrip;
}
else if (e.Button == MouseButtons.Right)
{
this.appNotifyIcon.ContextMenuStrip = this.rightContextMenuStrip;
}
this.appNotifyIcon.ContextMenuStrip.Show();
}

gqlu at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

Hi,

Sorry for the delay in responding.

Thanks for the help! I did manage to resolve the issue by rewriting the routine... which did incidentally incorporate a .Show method... probably why the re-written routine worked :)

Kind regards,

Deskman

Deskman at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Glad to hear your feedback that you have figured it out.
gqlu at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

Did anyone get the same problem with me when left-click the tray icon to show the contextmenustrip?

Here is my problem~~

my code to show the same contextmenustrip when left or right click the notifyicon

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{

notifyIcon1.ContextMenuStrip.Show();

}

When i right-click the notify icon, it works to show the context menu.

When i left-click the notify icon, it also works to show the context menu but some other thing happens unexpectedly.

It also show a main form on the windowns taskbar.

I don't know why. Can someone figure out this for me?

Thanks.

nemokao at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5

I have the same problem when i click the systray icon to view the context menu.

A new application is shown in the taskbar

Dijkstra30 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...