您好我想将鼠标移动到图片框内的X,Y坐标我从我的Sub获取我的坐标喜欢这个
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
LocalMousePosition = PictureBox1.PointToClient(Cursor.Position)
txt_MouseLoc.Text = ("X=" & LocalMousePosition.X & "," & "Y= " & LocalMousePosition.Y)
End Sub
现在假设x = 100且Y = 100
我想点击一个按钮并将鼠标移动到...你猜对了x100 y100
但我用这个来移动鼠标
Windows.Forms.Cursor.Position = New Point(x, y)
Thread.Sleep(2000)
Do_LMouseClick()
Thread.Sleep(2000)
根据屏幕将鼠标移动到x100和y100而不是picturebox1
我试过了
MouseLocation = picturebox1.pointtoscreen(x,y)
但没有任何想法?谢谢你提前!
答案 0 :(得分:1)
The location needs to add the form's location and picturebox's location:
Windows.Forms.Cursor.Position = New Point(x + Me.Location.X + PictureBox1.Location.X, _
y + Me.Location.Y + PictureBox1.Location.Y)
UPDATE:
The form's title bar needs to be compensated by adding its height in the Y equation.