473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

NotifyIcon and ContextMenu

Can anyone tell me if there is a workable method to get the mouse cursor
position on the screen or the NotifyIcon position? I need to display a
context menu for the NotifyIcon when clicked and I'd like it to display
based on the relative position of the tray icon or mouse pointer if
possible (whichever method works).

Any help would be much appreciated.

- Glen
Nov 16 '05 #1
3 10947
For the NotifyIcon I believe you need to write your own event
handler/message parsing loop and catch the mouse move's when the
NotifyIcon window appears.

Glen wrote:
Can anyone tell me if there is a workable method to get the mouse cursor
position on the screen or the NotifyIcon position? I need to display a
context menu for the NotifyIcon when clicked and I'd like it to display
based on the relative position of the tray icon or mouse pointer if
possible (whichever method works).

Any help would be much appreciated.

- Glen

Nov 16 '05 #2
Glen,

What's wrong with using the ContextMenu property on the NotifyIcon
class? Or do you mean you need the context menu to come up when it is
left-clicked (as opposed to right-clicked)?

If that is the case, then I don't know if you can do that in .NET 1.1
(unless you do all of the interop code yourself and create your own tray
icon, forgoing the NotifyIcon class).

In .NET 2.0, the NotifyIcon class has new events to handle the mouse
down and mouse up events over the NotifyIcon.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Glen" <Bu****@hotmail.com> wrote in message
news:O$*************@TK2MSFTNGP09.phx.gbl...
Can anyone tell me if there is a workable method to get the mouse cursor
position on the screen or the NotifyIcon position? I need to display a
context menu for the NotifyIcon when clicked and I'd like it to display
based on the relative position of the tray icon or mouse pointer if
possible (whichever method works).

Any help would be much appreciated.

- Glen

Nov 16 '05 #3
Hi Greg,

Actually, I found an article in Google Groups that helped by creating a
form control object to reference:

private void ShowMenu()
{
Control control = new Control();
control.CreateControl();
Point menuPos = new Point(Cursor.Position.X, Cursor.Position.Y);
notifyIcon1.ContextMenu.Show(control, menuPos);
}

I still have to run some tests to see what kind of overhead this
produces and how to compensate, but it seems to work. Now the only
problem I have is when the icon is right-clicked, the event is fired
twice (once when right-clicking the icon and once when clicking the menu
option). I just need to figure out how to call a single event
regardless of right or left click.

Thanks for your help.

- Glen

Greg Merideth wrote:
For the NotifyIcon I believe you need to write your own event
handler/message parsing loop and catch the mouse move's when the
NotifyIcon window appears.

Glen wrote:
Can anyone tell me if there is a workable method to get the mouse
cursor position on the screen or the NotifyIcon position? I need to
display a context menu for the NotifyIcon when clicked and I'd like it
to display based on the relative position of the tray icon or mouse
pointer if possible (whichever method works).

Any help would be much appreciated.

- Glen

Nov 16 '05 #4

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

Similar topics

0
by: petterl | last post by:
I have tried to find the error in the code below but I always get " An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object...
1
by: Chris Melnick | last post by:
I am trying to write an application that runs in the system tray, so I am using a NotifyIcon not associated with a Form. My "main" class has an instance of the NotifyIcon, and its ContextMenu, as...
0
by: Mike Allen | last post by:
Hi Everyone, My problem concerns ContextMenus. It's easy enough to create one and apply it to a NotifyIcon. When it's compiled and run, it works beautifully. Right click and there you are. But I...
3
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the...
2
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to...
4
by: Claire | last post by:
Sorry Ive added this twice (sortof) but if I'd added an addendum to the first one then this would probably have been ignored. This problem affects a ContextMenu attached to a NotifyIcon object. I...
12
by: mdb | last post by:
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...
4
by: nospam | last post by:
I am using VB Net 2005 and want to use the notifyicon. I do not have a form, only a class. I have no problems showing or modifying the NotifyIcon, however, I am having a problem handling the...
8
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.