Solved

NotifyIcon Mouse Events

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net Tranfer data between to VB.Net apps 8 44
How to limit User Input 2 33
vb.net Configuration, settings file location? 8 42
Web page design problem 3 14
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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