469,934 Members | 2,757 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Display menu on notifyIcon with left mouse click?

mdb
My app has a notify icon in the systray. I want the left mouse click to
initiate a menu, and a right-mouse click to do something else. Normally,
for a button, I would listen to MouseDown and if I need to display the
menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do
this for a notifyIcon because notifyIcons aren't controls. How can I
display a contextMenu where the cursor is by command only?

-mdb
Nov 17 '05 #1
12 17789
Unfortunately you can not do this. But you can handle click events for
notify icon and show your own contextr menu.. But it could be hard to
control position of the menu and when to hide menu....

--

Thanks,
Yunus Emre ALP÷ZEN
BSc, MCAD.NET

"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
My app has a notify icon in the systray. I want the left mouse click to
initiate a menu, and a right-mouse click to do something else. Normally,
for a button, I would listen to MouseDown and if I need to display the
menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do
this for a notifyIcon because notifyIcons aren't controls. How can I
display a contextMenu where the cursor is by command only?

-mdb

Nov 17 '05 #2
mdb wrote:
My app has a notify icon in the systray. I want the left mouse click to
initiate a menu, and a right-mouse click to do something else. Normally,
for a button, I would listen to MouseDown and if I need to display the
menu, I would contextMenu.Show(buttonCtrl, new Point(0)). But I can't do
this for a notifyIcon because notifyIcons aren't controls. How can I
display a contextMenu where the cursor is by command only?

-mdb

Hi,
The notify Icon has a context menu property.
Create your context menu and then associate that menu with your notify
icon at design time (or run time) and it will automagically pop up.

HTH
JB
Nov 17 '05 #3
mdb
"Wayne" <Me******@community.nospam> wrote in news:ODM18bYVFHA.1796
@TK2MSFTNGP15.phx.gbl:
I'm still wondering why you would want to change the default standard
behavior. Depending on why I would find using your app very annoying and
probably uninstall it.


Well first of all, its a design consideration that shouldn't concern anyone
but me and my customers. Many of them have expressed that they want the
menu to appear on the left mouse click, because this is the "primary
function" of the program. They want a window to appear when a right-click
occurs because this is a "secondary function" of the program.

Second of all, I'm not planning to force this on anyone - it will be an
option. If you want it the way you want it, fine. But the problem still
exists that I can't do what they are asking me to do, which is why I'm
looking for some help here.

-mdb
Nov 17 '05 #4
mdb
"Yunus Emre ALP÷ZEN [MCAD.NET]" <ye***@msakademik.net> wrote in
news:e2**************@TK2MSFTNGP12.phx.gbl:
Show your menu manually. Call its Show method.. Assign this as first
parameter; assign a Point that u calculate for position. For instance;

new Point(Screen.PrimaryScreen.Bounds.Width-Left),
Screen.PrimaryScreen.Bounds.Height-Top)

This shows your menu @right bottom corner.But you have to decide when to
clsoe context menu...


Ummmm.... the Show(...) method for a ContextMenu is

[C#]
public void Show(
Control control,
Point pos
);

What would I use for the 'Control'? If I set it to 'null', I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: 'null' is not a valid value for 'control'.

-mdb
Nov 17 '05 #5
this

--

Thanks,
Yunus Emre ALP÷ZEN
BSc, MCAD.NET

"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Yunus Emre ALP÷ZEN [MCAD.NET]" <ye***@msakademik.net> wrote in
news:e2**************@TK2MSFTNGP12.phx.gbl:
Show your menu manually. Call its Show method.. Assign this as first
parameter; assign a Point that u calculate for position. For instance;

new Point(Screen.PrimaryScreen.Bounds.Width-Left),
Screen.PrimaryScreen.Bounds.Height-Top)

This shows your menu @right bottom corner.But you have to decide when to
clsoe context menu...


Ummmm.... the Show(...) method for a ContextMenu is

[C#]
public void Show(
Control control,
Point pos
);

What would I use for the 'Control'? If I set it to 'null', I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: 'null' is not a valid value for 'control'.

-mdb

Nov 17 '05 #6
mdb
"Yunus Emre ALP÷ZEN [MCAD.NET]" <ye***@msakademik.net> wrote in news:
#N**************@TK2MSFTNGP09.phx.gbl:
this


OK... This helped me get much closer to solving the problem, but simply
setting 'this' isn't the full answer, although it did help, and I'm still
not quite where I need to be. Read on for details...

If I call

notifyIcon1.Show(this, new Point(0,0))

then the menu appears in the upper left-hand corner of the screen instead
of where my notifyIcon is, because 'this' is a windows form that is
minimized. For a while, it seemed like no matter what I put for the point
(even Cursor.Position), it always appeared in the upper left-hand corner.
But then I realized that the value of Form.Location for a minimized form is
(-32000, -32000), and these extreme values were just overriding the small
values I was using. So instead of Point(0) or Cursor.Position, I did this:

notifyIcon1.Show(this, this.PointToClient(Cursor.Position))

which works quite well. (I don't mind if the Menu shows where the cursor
is instead of exactly where the notifyIcon is.)

BUT... now I can't exit my menu???? That is, if I choose NOT to click
any of my items, I can't get the menu to go away. I press ESC, I click
outside of the menu window... the ContextMenu still stays up. This is NOT
a problem when the ContextMenu is used in the normal manner with the
notifyIcon.ContextMenu property.

So now my question is... How can I get the ContextMenu to go away when I
click outside of it or press ESC if I am displaying it using the Show(...)
method? I could just put a dummy "Exit Menu" item that does nothing, but
that is kind of cheesy.

Getting closer - thanks!

-mdb
Nov 17 '05 #7
mdb
mdb <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in
news:Xn****************************@207.46.248.16:
BUT... now I can't exit my menu???? That is, if I choose NOT to
click any of my items, I can't get the menu to go away. I press ESC,
I click outside of the menu window... the ContextMenu still stays up.
This is NOT a problem when the ContextMenu is used in the normal
manner with the notifyIcon.ContextMenu property.

So now my question is... How can I get the ContextMenu to go away
when I click outside of it or press ESC if I am displaying it using
the Show(...) method? I could just put a dummy "Exit Menu" item that
does nothing, but that is kind of cheesy.


Interesting thing I found... if I click my MenuItems, then it works the
way I would want, but if I simply mouse over them, and then click off of
the menu, it does not exit. So this seems to be more of a mouse capture
issue than anything else.

-mdb
Nov 17 '05 #8
mdb wrote:
John B <jb******@yahoo.com> wrote in
news:42***********************@news.sunsite.dk:

Hi,
The notify Icon has a context menu property.
Create your context menu and then associate that menu with your notify
icon at design time (or run time) and it will automagically pop up.

You misunderstand (or I didn't make it clear enough). I already have a
ContextMenu associated with the notifyIcon. The problem is that I want to
swap the meaning of the left/right mouse button, so I want the ContextMenu
to appear when I click the LEFT mouse button (it normally appears with the
right button.) And I want to perform a custom action with the RIGHT mouse
button.

Now, I can catch the left and right mouse clicks without any problem. The
problem occurs when, on a left mouse click, how to get the ContextMenu to
appear, because the Show(...) method of ContextMenu requires a
System.Windows.Forms.Control, which NotifyIcon is not.

-mdb


Doh,
Sorry, I really should read the post twice before answering.

JB
:)
Nov 17 '05 #9
Wasn't trying to offend you by saying that. I've just seen time and time
again where new developers have tried to change the default, normal,
expected behavior of their app so that it was different than everything else
with out thinking fully of the effects on their potential customers of doing
it. So questioning that usually makes them think about it a bit more. It is
obvious now that you have thought about that.

Wayne
"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Wayne" <Me******@community.nospam> wrote in news:ODM18bYVFHA.1796
@TK2MSFTNGP15.phx.gbl:
I'm still wondering why you would want to change the default standard
behavior. Depending on why I would find using your app very annoying and
probably uninstall it.

Well first of all, its a design consideration that shouldn't concern

anyone but me and my customers. Many of them have expressed that they want the
menu to appear on the left mouse click, because this is the "primary
function" of the program. They want a window to appear when a right-click
occurs because this is a "secondary function" of the program.

Second of all, I'm not planning to force this on anyone - it will be an
option. If you want it the way you want it, fine. But the problem still
exists that I can't do what they are asking me to do, which is why I'm
looking for some help here.

-mdb

Nov 17 '05 #10
Instead of hiding the form, move it off screen and then in the contextmenus
popup event call this.Activate()

Alternatively ou could pInvoke SetForegroundWindow.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Wayne" <Me******@community.nospam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Wasn't trying to offend you by saying that. I've just seen time and time
again where new developers have tried to change the default, normal,
expected behavior of their app so that it was different than everything
else
with out thinking fully of the effects on their potential customers of
doing
it. So questioning that usually makes them think about it a bit more. It
is
obvious now that you have thought about that.

Wayne
"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Wayne" <Me******@community.nospam> wrote in news:ODM18bYVFHA.1796
@TK2MSFTNGP15.phx.gbl:
> I'm still wondering why you would want to change the default standard
> behavior. Depending on why I would find using your app very annoying
> and
> probably uninstall it.
>


Well first of all, its a design consideration that shouldn't concern

anyone
but me and my customers. Many of them have expressed that they want the
menu to appear on the left mouse click, because this is the "primary
function" of the program. They want a window to appear when a
right-click
occurs because this is a "secondary function" of the program.

Second of all, I'm not planning to force this on anyone - it will be an
option. If you want it the way you want it, fine. But the problem still
exists that I can't do what they are asking me to do, which is why I'm
looking for some help here.

-mdb


Nov 17 '05 #11
mdb
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in news:#l**************@tk2msftngp13.phx.gbl:
Instead of hiding the form, move it off screen and then in the
contextmenus popup event call this.Activate()

Alternatively ou could pInvoke SetForegroundWindow.


Yeah I thought about moving it off screen, and it seemed to work pretty
well, but I went back (never tried the Activate method). Thanks for the
tip - I'll try this to see if it works any better.

-mdb
Nov 17 '05 #12
If you are moving it off screen be sure to check the Screen object and
position the form so it will truly be off screen. I have two monitors where
my secondary is to the left, so the cords on it are all negative. Not sure
if your customers would have this issue or not, just something else to be
careful of.

--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in news:#l**************@tk2msftngp13.phx.gbl:
Instead of hiding the form, move it off screen and then in the
contextmenus popup event call this.Activate()

Alternatively ou could pInvoke SetForegroundWindow.


Yeah I thought about moving it off screen, and it seemed to work pretty
well, but I went back (never tried the Activate method). Thanks for the
tip - I'll try this to see if it works any better.

-mdb

Nov 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by JesusFreak | last post: by
2 posts views Thread by RWD | last post: by
3 posts views Thread by SteveMac | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.