Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1407
  • Last Modified:

NotifyIcon Mouse Events

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
JeffN825
Asked:
JeffN825
  • 2
1 Solution
 
sowynCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
JeffN825Author Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now