Solved

NotifyIcon Mouse Events

Posted on 2004-10-08
4
1,348 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

11 Experts available now in Live!

Get 1:1 Help Now