VB.net-在表格外获取鼠标坐标 [英] VB.net -- Getting mouse coordinates outside the form
问题描述
我正在Vb.net中编写一个简单的程序来收集信息。例如鼠标x y坐标,像素颜色和击键数字。我希望能够在屏幕上的任何地方而不是仅在表格上查看光标的x和y坐标,并且我想以最简单的方式做到这一点。我达到预期效果的一种方法是使用以下设置:
I'm writing a simple program in Vb.net that collects information. such things as mouse x y coordinates, Pixel color, and keystroke numbers. I would like to be able to view the x and y coordinates of the cursor anywhere on the screen instead of just over the form, and i would like to do this in the simplest way possible. One way i have achieved the desired effect is with the following settings:
Picturebox2:
Picturebox2:
- BackColor =红色
- image = 3 x 2像素的图像(几乎可见,但必须全部相同)
Form1:
- 透明键=红色
这将导致在光标位于表单边界之外时显示鼠标坐标。但是它仍然在表格上。我为此特定问题使用的代码是:
This results in the appearance of the mouse coordinates being displayed while the cursor is outside the form boundaries. however it's still over the form. The code i'm using for this particular problem is:
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
Im running Visual Studio 2010 on a Windows 7 x64 Sony VAIO
推荐答案
一种非常简单的方法是在Form v中捕获鼠标ia Me.Capture = True。详情请参阅此处。
A really simple way would be to Capture the mouse in the Form via Me.Capture = True. See here for details:
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.capture.aspx
也就是说,即使您不是活动的应用程序,也需要跟踪鼠标,则必须使用某种类型的挂钩。不清楚您到底想做什么。
That being said, if you need to track the mouse even when you are not the active application you are going to have to use some type of hooking. Not clear exactly what you are looking to do though.
这篇关于VB.net-在表格外获取鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!