2
我試圖隱藏鼠標指針,當有幾秒鐘的不活動時,然後當用戶移動鼠標時再次顯示指針。我已經能夠讓鼠標指針隱藏並重新顯示,但是當我執行grid.Children.Clear()
和grid.Children.Add()
時,鼠標指針重新出現(但是在幾秒鐘不活動之後再次隱藏)。隱藏鼠標指針
我的代碼如下:
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
我想知道,這是一個已知的問題,或者是有什麼實現,我試圖做的更好的辦法?
感謝,
馬特