1 Attachment(s)
VB.NET - How to move the mouse in a specific range in the panel
Visual Basic.Net
Hello everyone.
In this photo , there is a panel.
What I want to do is moving the mouse in specific range in the panel.
When the mouse will be in the panel , I want the mouse to move in specific range.
What I mean by specific range ?
I mean by that , Moving the mouse in X Axis from 95 to 493.
And moving the mouse in Y Axis start from 30.5.
and this specific range in the panel.
How can I do this ?
Attachment 188560
Re: VB.NET - How to move the mouse in a specific range in the panel
I don't think you can do it using a PointF (coordinates that use decimal values) but here's a solution that works with using a Point (coordinates that use integer values):
Code:
Public Class Form1
Private ReadOnly _random As New Random()
Private Function GetRelativeLocation(childControl As Control, location As Point) As Point
Dim screenX = childControl.PointToScreen(location).X
Dim screenY = childControl.PointToScreen(location).Y
Return New Point(screenX, screenY)
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x = _random.Next(95, 493 + 1)
Dim y = 30
Dim cursorLocation = GetRelativeLocation(Panel1, New Point(x, y))
Cursor.Position = cursorLocation
End Sub
End Class
All I did was add a button to the form to trigger moving the cursor since you didn't specify what the trigger is.
Re: VB.NET - How to move the mouse in a specific range in the panel
You can specify a restrictive bounding rectangle with cursor.clip