Solved

NotifyIcon Mouse Events

Posted on 2004-10-08
4
1,354 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
  • 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 85

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now