how can notify icon present its context menu on both left and right button click

A

assaf

hi all

i have a form with a notifyIcon.
when i right mouse button click it,
it displays its context menu.

however, i would like it
to present this menu upon
left mouse button click as well.


how can i do this?


assaf
 
S

Shiva

In the NotifyIcon's click-event, call the Show() method of the context menu.


hi all

i have a form with a notifyIcon.
when i right mouse button click it,
it displays its context menu.

however, i would like it
to present this menu upon
left mouse button click as well.


how can i do this?


assaf
 
A

assaf

hi shiva.

this is my code.
with your help.
however, the position is not correct.
what sould the parameters for show be?
this.contextMenu1.Show(this, Cursor.Position);


assaf
 
S

Shiva

Cursor.Position gives the current position in screen-coordinates. Use
NotifiyIcon's MouseUp event. Its MouseEventArgs gives the X/Y coordinates.

hi shiva.

this is my code.
with your help.
however, the position is not correct.
what sould the parameters for show be?
this.contextMenu1.Show(this, Cursor.Position);


assaf
 
A

assaf

hi shiva.

here is my code.
i don't know what to put in the first parameter of the Show call.

private void notifyIcon1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);
this.contextMenu1.Show(???????what should i put here?????????????, p);
}




assaf
 
S

Shiva

Hi,
You may use the NotifyIcon reference for the 1st parameter of the Show()
method.

hi shiva.

here is my code.
i don't know what to put in the first parameter of the Show call.

private void notifyIcon1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);
this.contextMenu1.Show(???????what should i put here?????????????, p);
}




assaf
 
A

assaf

hi shiva

i tried this code:

private void notifyIcon1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);

this.contextMenu1.Show(/***************/this.notifyIcon1/*******************
*******/, p);
}

but i get these errors:
The best overloaded method match for
'System.Windows.Forms.ContextMenu.Show(System.Windows.Forms.Control,
System.Drawing.Point)' has some invalid arguments
Argument '1': cannot convert from 'System.Windows.Forms.NotifyIcon' to
'System.Windows.Forms.Control'


assaf
 
S

Shiva

My mistake. Try passing the form reference itself (Me).

Sorry again :-(

hi shiva

i tried this code:

private void notifyIcon1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point p = new Point(e.X, e.Y);

this.contextMenu1.Show(/***************/this.notifyIcon1/*******************
*******/, p);
}

but i get these errors:
The best overloaded method match for
'System.Windows.Forms.ContextMenu.Show(System.Windows.Forms.Control,
System.Drawing.Point)' has some invalid arguments
Argument '1': cannot convert from 'System.Windows.Forms.NotifyIcon' to
'System.Windows.Forms.Control'


assaf
 
A

assaf

hi shiva.

don't be sad.
you are helping me very much.

i tried Me,
but the menu gets displayed in the form itself.
just as if i clicked the first menu item in a menu.


assaf
 
S

Shiva

Hi,
The position specified as the second parameter for the ContextMenu.Show() is
within the control -the first param (in this case, it is the form itself).
So, X & Y values may have to be adjusted accordingly. But, the context menu
may not be positioned exactly as with the case of right-click.

hi shiva.

don't be sad.
you are helping me very much.

i tried Me,
but the menu gets displayed in the form itself.
just as if i clicked the first menu item in a menu.


assaf
 
A

assaf

hi shiva.

why does Cursor.Position not work?
what is your best estimate for the proper Position?


assaf
 
A

assaf

hi

where can i find an example for this?
there must be some open code,
even in C++.


assaf
 
S

Shiva

Hi,
Since Cursor.Position is in screen coordinates and it is taken with respect
to the specified control's (1st parameter) position on the screen while
showing the context menu, I believe there will be some offset. But, I am not
sure of any method to give the exact positioning like right-button click.

hi shiva.

why does Cursor.Position not work?
what is your best estimate for the proper Position?


assaf
 
J

Jeff Gaines

hi

where can i find an example for this?
there must be some open code,
even in C++.


assaf

You may need to use PointToClient:

Point pos = this.PointToClient(MousePosition);
mnuLVCtx.Show(this, pos);

Also look at PointToScreen, I am never sure which to use and usually
end up experimenting :)
 

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