【问题标题】:VB.net -- Getting mouse coordinates outside the formVB.net——在表单外获取鼠标坐标
【发布时间】:2014-08-15 04:03:09
【问题描述】:

我正在用 Vb.net 编写一个收集信息的简单程序。例如鼠标 x y 坐标、像素颜色和击键数。我希望能够在屏幕上的任何位置而不是在表单上查看光标的 x 和 y 坐标,并且我希望以最简单的方式做到这一点。我达到预期效果的一种方法是使用以下设置:

图片框2:

  • BackColor = 红色
  • 图像 = 3 x 2 像素图像(几乎不可见,但同样需要)

表格1:

  • 透明键 = 红色

这会导致鼠标坐标的外观在光标位于表单边界之外时显示。但是它仍然超出了表格。我用于这个特定问题的代码是:

Dim mouseloc As Point


Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    mouseloc = Cursor.Position
    lblc.Text = PointToClient(mouseloc).ToString
    lbls.Text = PointToScreen(mouseloc).ToString
End Sub

Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
    mouseloc = Cursor.Position
    lblc.Text = PointToClient(mouseloc).ToString
    lbls.Text = PointToScreen(mouseloc).ToString
End Sub

我在 Windows 7 x64 Sony VAIO 上运行 Visual Studio 2010

【问题讨论】:

  • 如果你弄明白了,能不能把答案贴出来,我也在找同样的东西,谢谢

标签: vb.net transparency coordinates


【解决方案1】:

一个非常简单的方法是通过 Me.Capture = True 在表单中捕获鼠标。详情请看这里:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.capture.aspx

话虽如此,如果即使您不是活动应用程序也需要跟踪鼠标,您将不得不使用某种类型的挂钩。虽然不清楚你想要做什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多