Set MouseHoverTime

larkahn

Member
Joined
Sep 10, 2006
Messages
18
Programming Experience
1-3
I have a lot of buttons that I am creating audio hints for. I would like to set the mousehovertime to require a longer hover time before the playing of the file occurs. I did find a post on MSDN, which is not in VB .NET and seems complicated. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=944389&SiteID=1 Below is the code I have for playing the file. My programming skills are very limited.

VB.NET:
Private Sub Button1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseHover
      'If toggle is set to false, no audio help is available on MouseHover.  
If audio = False Then
            Exit Sub
        End If
       
'If toggle is set to true, the play the file.
       
 My.Computer.Audio.Play((App_Path() & "i_in_eat_NEO.wav"), _
           AudioPlayMode.WaitToComplete)
    End Sub
 
That example don't use the MouseHover event, but instead the MouseMove and MouseLeave events in combination with a Timer.

With mouse move the timer is started, with mouse leave the timer is stopped.

There is used one boolean variable to make the "hover' effect only happen once, this is checked first in mouse move and is reset in mouse leave.

When the timer Tick event happens it does the 'hover' action and also sets the boolean true to tell that current 'hover' was done.


A tip: you can use the same mousemove and mouseleave event handlers for all controls you need this for, you also only need a single timer (just use a variable to tell what control you need to play the hover effect for) - so you only need to write these three sub methods as described.
 
I think I understand. What the MSDN article means is that the only way to modify the MouseHoverTime property is through an API and this affects the entire computer. Therefore the way around this is to use the timer and other events. My only other question is, why use the mousemove? Couldn't I just use the mouseenter (and mouseleave)? The timer starts on entering the control, and if I leave the control (mouseleave)before the timer countdown expires, the timer would be disabled and the action wouldn't occur.
 
You could do that if you wanted the hover effect when there was a enter-without-leave exclusively.

The alterative is that the hover effect doesn't occur until there is a certain lack of movement over the control. When you use mousemove this happens a lot and the timer is to be restarted (timing from start) every time until there is no movement. The example you linked also calculated and allowed a very minimal spot movement (4 pixels x/y direction) within the hover range that continues the hover timer.

Btw, that was not an official MSDN article, but a forum post.
 
Back
Top