Search code examples
vb.neteventstimermousegroupbox

Detect if mouse stop moving vb.net


I would like to stop the timer whenever a mouse stops moving inside a groupbox

As of now, I start the timer when the mouse hover at the groupbox and stops it when it leaves the group box.

Private Sub gbxMouseMap_MouseHover(sender As Object, e As System.EventArgs) Handles gbxMouseMap.MouseHover
    Timer.Start()
End Sub

Private Sub gbxMouseMap_MouseLeave(sender As Object, e As System.EventArgs) Handles gbxMouseMap.MouseLeave
    Timer.Stop()
End Sub

Solution

  • In the MouseMove event set a class varible named LastMoveTime to the current timer elapsed time. In the MouseHover event check to see if LastMoveTime has reached the timeout period, if so stop the timer.

    I will get you started...

    Private LastMoveTime As DateTime
    Private MouseTimeoutMilliseconds as Integer = 500 
    
    
    'put inside hover
    
    If  LastMoveTime.AddMilliseconds(MouseTimeoutMilliseconds) < Now Then
     Timer.Stop()
    Else
     Timer.Start()
    End if