我正在使用Vb.net编写一个简单的程序,用于收集信息,例如鼠标坐标、像素颜色和按键数量。我希望能够在屏幕的任何位置查看光标的x和y坐标,而不仅仅是在表单上,并且我希望以最简单的方式实现这一点。我已经通过以下设置实现了所需的效果:
Picturebox2: BackColor = Red image = 3 x 2像素图像(几乎不可见,但仍然需要)
Form1: Transparency key = Red
这将导致显示光标坐标,即使光标在窗体边界之外。但是它仍然在窗体上。我用于解决这个特定问题的代码是:
Picturebox2: BackColor = Red image = 3 x 2像素图像(几乎不可见,但仍然需要)
Form1: Transparency key = Red
这将导致显示光标坐标,即使光标在窗体边界之外。但是它仍然在窗体上。我用于解决这个特定问题的代码是:
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。