WPF:如何在代码中定位鼠标光标?

发布于 2024-08-21 20:02:14 字数 89 浏览 5 评论 0原文

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

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

I am implementing the system menu (Restore, Move, Size...) on a borderless window, and I want the mouse cursor to move to the center of the Window when size or move is selected.

Ideally in VB but C# is fine as well.

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

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

发布评论

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

评论(2

月竹挽风 2024-08-28 20:02:14

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

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

'...

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

You can use the SetCursorPos function, something like:

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

'...

dim p as point
p.x = 100
p.y = 200
SetCursorPos p
再可℃爱ぅ一点好了 2024-08-28 20:02:14

进行一些调整,似乎有效:

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

A few tweaks and it seems to work:

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