Jump to content
  • Advertisement
Sign in to follow this  

Get and set mouse position

This topic is 3440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can any one tell me.... How to get and set mouse position within form(for window application)? I am using c# 2008 studio. I am new to it , so please reply though the question is stupid.

Share this post


Link to post
Share on other sites
Advertisement
    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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!