I am attempting to hide the mouse pointer when there has been a few seconds of inactiv开发者_如何学运维ity and then re-show the pointer again when the user moves the mouse. I have been able to get the mouse pointer to hide and re-show as I require it, however when I execute grid.Children.Clear()
and grid.Children.Add()
the mouse pointer re-appears (but again hides after a few seconds of inactivity).
My code is as below:
Private Sub Window1_MouseMoved(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
'MsgBox("Mouse Has Moved", MsgBoxStyle.Critical, "Mouse Moved")
LastMouseMove = DateTime.Now
If IsHidden Then
Cursor = Cursors.Arrow
IsHidden = False
End If
End Sub
Private Sub MouseHide_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim elaped As TimeSpan = DateTime.Now - LastMouseMove
If elaped >= TimeoutToHide AndAlso Not IsHidden Then
Cursor = Cursors.None
IsHidden = True
'System.Console.SetCursorPosition(0, 0)
End If
End Sub
Private Sub setupMouseHide()
Try
'Dim timer As New System.Timers.Timer(1000)
Dim dispatcherTimer As DispatcherTimer = New System.Windows.Threading.DispatcherTimer()
AddHandler dispatcherTimer.Tick, AddressOf MouseHide_Tick
dispatcherTimer.Interval = New TimeSpan(0, 0, 3)
dispatcherTimer.Start()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Setup Display Message: error encountered")
End Try
End Sub
I was wondering if this is a known issue or is there a better way of achieving what I am seeking to do?
Thanks,
Matt
It might be a bug, but its not uncommon for layout changes to cause a mouse move event to be raised.
I'd say your best bet might be to check and store the actual coordinates of the mouse in that mouse move event. That way you can ignore the errant mouse move events.
Not ideal, but I think it would work.
精彩评论