WPF:如何将鼠标光标放在代码中?

时间:2010-02-15 21:42:41

标签: wpf mouse cursor position move

我正在无边框窗口上实现系统菜单(恢复,移动,大小...),我希望在选择大小或移动时鼠标光标移动到窗口的中心。理想情况下在VB中,但C#也很好。

2 个答案:

答案 0 :(得分:2)

您可以使用SetCursorPos功能,例如:

Declare Function SetCursorPos& Lib "user32" (ByVal p As Point)

'...

dim p as point
p.x = 100
p.y = 200
SetCursorPos p

答案 1 :(得分:1)

一些调整似乎有效:

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