隐藏鼠标指针

发布于 2024-11-07 07:08:09 字数 1299 浏览 0 评论 0原文

我试图在几秒钟不活动时隐藏鼠标指针,然后在用户移动鼠标时再次重新显示指针。我已经能够根据需要隐藏并重新显示鼠标指针,但是当我执行 grid.Children.Clear() 和 grid.Children.Add()< /code> 鼠标指针重新出现(但在几秒钟不活动后再次隐藏)。

我的代码如下:

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 am attempting to hide the mouse pointer when there has been a few seconds of inactivity 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2024-11-14 07:08:09

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文