Solved

NotifyIcon Mouse Events

Posted on 2004-10-08
4
1,389 Views
Last Modified: 2012-06-22
I have a really simple question, but given my experience is with VB6 and not VB .NET, I am having some trouble.

I have a application that runs in the system tray as a NotifyIcon.  I need to have certain mouse enter and mouse leave event functions.  Specifically, I need the icon for the NotifyIcon to change on mouse over, and then change back on mouse leave.

I have not been able to figure out how to do this using MouseMove, which appears to be the only applicable event VB .NET has.

How can I accomplish this functionality in VB .NET?

Thanks
0
Comment
Question by:JeffN825
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:sowyn
ID: 12265999
Hi!

  In VB.NET the things are a bit more easy.

Try this:

1) Create a new Windows Application project. In the default created form, insert a NOTIFYICON component (you can find it in the toolbox, between the "Windows Form" group components).
2) Insert this code:
   Private Sub NotifyIcon1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseMove
        MsgBox("TEST")
   End Sub
3) Go to the NOTIFYICON component properties and set the ICON value using an ICO image.

Now, you can start the test application. When you start this project, you will see the form on the screen and a Tray icon in the right bottom corner.

With the code inserted at the point 2), when you mouse over the tray icon, the application begins to show message boxes saying "TEST".

Note: the NOTIFYICON MouseOver event isn't the FORM MOUSE OVER EVENT!

Hoping to be useful, Bye, Sowyn.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12266230
Hi JeffN825,

I know of no clean way to determine when the mouse enters or leaves your icon in the tray.  The icons in the tray do not have their own window and you cannot predict their absolute position in coordinates with any degree of certainty since their may be other icons in the tray and the entire taskbar can be docked to any side of the screen and resized at will by the user.

I think the closest you could get is to store the coordinates of the cursor on your first mouse move event and then start a polling timer.  If the cursor leaves a "proximity" region then you can change the icon back and stop your timer.  It would be inexact since you wouldn't know where the first coordinates would be relative to the overall position of your tray icon.

Hope somebody can prove me wrong,

~IM
0
 
LVL 1

Author Comment

by:JeffN825
ID: 12277757
So, can someone plese prove you wrong?

The way I currently have this implemented is as described by Idle Mind.

I was hoping for a more intuitive solution.

Thanks.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12277818
Since the tray interface doesn't have a function to determine if a point is contained by an icon, and the icons themselves don't have windows, I don't think you are going to find an elegant solution.  It just doesn't seem possible with the current windows architecture.

~IM
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question