【问题标题】:Hide Mouse Pointer隐藏鼠标指针
【发布时间】:2011-08-24 16:03:00
【问题描述】:

我试图在几秒钟不活动时隐藏鼠标指针,然后在用户移动鼠标时再次重新显示指针。我已经能够根据需要隐藏和重新显示鼠标指针,但是当我执行 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

我想知道这是一个已知问题,还是有更好的方法来实现我想要做的事情?

谢谢,

马特

【问题讨论】:

    标签: wpf vb.net .net-3.5


    【解决方案1】:

    这可能是一个错误,但布局更改导致鼠标移动事件引发的情况并不少见。

    我想说您最好的选择可能是在该鼠标移动事件中检查并存储鼠标的实际坐标。这样您就可以忽略错误的鼠标移动事件。

    不理想,但我认为它会工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      相关资源
      最近更新 更多