472,805 Members | 850 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 10899
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.