views:

860

answers:

2

I have a NotifyIcon control that appears in the system tray. How can I find the location (x, y) of the icon on the screen?

Thanks

+1  A: 

You can't. It isn't hard to get the window handle for the system tray, GetClassName() returns "ToolbarWindow32", the class name of the standard TOOLBAR common control. Beware that a 64-bit OS has two of them. Then you can send messages to it like TB_GETBUTTONINFO. Chief hang-ups are that you won't know what button ID to choose and the returned info does not include the button position.

Which is for the better, buttons move around without you being able to lock them.

Hans Passant
thanks. I suspected this.
AngryHacker
A: 

Actually you can do this, here is code that shows you how and much more.

In any Mouse Event from NotifyIcon, simply look at Control.MousePosition, this contains the (x,y) of the mouse. The same can be done to position a ContextMenu on a form/control exactly where the form/control was clicked using these (x,y) values.

A good example of both of these is here:

More Here: http://code.msdn.microsoft.com/TheNotifyIconExample