Results 1 to 3 of 3

Thread: VB.NET - How to move the mouse in a specific range in the panel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2021
    Posts
    17

    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 ?

    Name:  Capture.jpg
Views: 933
Size:  6.6 KB
    Last edited by MohammedAnas Mohamme; Aug 25th, 2023 at 02:34 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width