【问题标题】:WPF: How do I position the mouse cursor in code?WPF:如何在代码中定位鼠标光标?
【发布时间】:2010-02-15 21:42:41
【问题描述】:

我正在无边框窗口上实现系统菜单(恢复、移动、大小...),并且我希望鼠标光标在选择大小或移动时移动到窗口的中心。

最好在 VB 中使用,但 C# 也可以。

【问题讨论】:

    标签: wpf position move mouse-cursor


    【解决方案1】:

    您可以使用SetCursorPos 函数,例如:

    Declare Function SetCursorPos& Lib "user32" (ByVal p As Point)
    
    '...
    
    dim p as point
    p.x = 100
    p.y = 200
    SetCursorPos p
    

    【讨论】:

      【解决方案2】:

      一些调整,它似乎工作:

      Private Declare Function SetCursorPos Lib "user32" (ByVal x As Int32, ByVal Y As Int32) As Int32
      

      ...

      With Win
      
        Dim left As Int32 = CInt(.Left + .Width - CURSOR_OFFSET_MEDIUM)
        Dim top As Int32 = CInt(.Top + .Height / 2)
      
        SetCursorPos(left, top)
      
      End With
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-08
        • 2021-07-10
        • 2013-09-15
        • 2011-04-19
        • 1970-01-01
        相关资源
        最近更新 更多