473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sho w(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 18334
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__c om> wrote in message
news:Xn******** *************** *****@207.46.24 8.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.Sho w(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.Sho w(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******@commu nity.nospam> wrote in news:ODM18bYVFH A.1796
@TK2MSFTNGP15.p hx.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***@msakadem ik.net> wrote in
news:e2******** ******@TK2MSFTN GP12.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.Pr imaryScreen.Bou nds.Width-Left),
Screen.PrimaryS creen.Bounds.He ight-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.Argumen tException' 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__c om> wrote in message
news:Xn******** *************** *****@207.46.24 8.16...
"Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakadem ik.net> wrote in
news:e2******** ******@TK2MSFTN GP12.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.Pr imaryScreen.Bou nds.Width-Left),
Screen.PrimaryS creen.Bounds.He ight-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.Argumen tException' 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***@msakadem ik.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.Sho w(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.Sho w(this, this.PointToCli ent(Cursor.Posi tion))

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.Cont extMenu 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__c om> wrote in
news:Xn******** *************** *****@207.46.24 8.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.Cont extMenu 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.d k:

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__c om> wrote in message
news:Xn******** *************** *****@207.46.24 8.16...
"Wayne" <Me******@commu nity.nospam> wrote in news:ODM18bYVFH A.1796
@TK2MSFTNGP15.p hx.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3842
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following beautiful script "http://javascript.internet.com/navigation/toolbar-menu.html". It works like a charm. I made my webpage in frames, where the nav-frame shows the menubar, so whenever I click a link in the menubar, it opens in the frame below. But...
1
4329
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i want to make first text as Table Heading/menu category. For examle in the given menu i want to make a heading as "Comp. Languages" which won't be a link. 2) The position of this menu is absolute to the page. I want to make it absolute to the Table...
2
5306
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance RWD <script type='text/javascript'>
4
5778
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
0
2024
by: Neo | last post by:
I have created a Windows Service that shows a notifyicon in the system tray. I have also created a context menu for the notifyicon and implemented the notifyicons click event. The notifyicon does appears correctly in the system tray while the service is running but the context menu does not pop up when the icon is right clicked. Nor does the click event fire when the icon is clicked. Any suggestions?
3
7424
by: SteveMac | last post by:
I am using VS2003 VC++ .NET. I want to make a tray icon with a popup menu (like a context menu) that pops up for a left click. I can make the notifyicon with a context menu and that works fine, but I really want it to show the menu for a left click, exactly as it would for a right click. SteveMac
2
3265
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully validated my HTML and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button once, a white window the size of my webpage displays. I close it and click on the button again (for...
8
8498
by: starrysky | last post by:
I have a program which puts an icon in the notification area and has a menu associated with it available by right clicking on the icon. I want the menu items to be selected by single left clicks but I also want the user to be able to single left click on the icon itself to do some other functionality. Here's the problem - the single click on the menu first fires the notifyicon1_click() routine and then the menuitem1_click() routine. How do I...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.