Sign in to follow this  
mytechgroup

Get and set mouse position

Recommended Posts

    private void Form1_MouseDown(object sender, MouseEventArgs e)
{
// get mouse position relative to Screen
int offsetFrom_ScreenOrigin_X = Cursor.Position.X;
int offsetFrom_ScreenOrigin_Y = Cursor.Position.Y;

// set mouse position relative to screen, e.g. at pixel (100, 100)
Cursor.Position = new Point(100, 100);

// get mouse position relative to a control (must be in any mouse event function)
int offsetFrom_Form1Origin_X = e.X;
int offsetFrom_Form1Origin_Y = e.Y;

// set mouse position relative to a control, e.g. at pixel (100, 100)
Cursor.Position = this.PointToScreen(new Point(100, 100));
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this