Advertisement Jump to content
Sign in to follow this  

mouse coordinats in game-window

This topic is 1774 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

Hi! I have a winform and a picturebox where my game is.


I want to get the mouse-coordinats for only the game-window and not the entire window.


How can I do this?

Share this post

Link to post
Share on other sites

What language are you using?



Ok after looking at a one of your past topics I figure that you're using c#.


After some research I found this it may help you. wink.png

Edited by Zedmonkeyboy

Share this post

Link to post
Share on other sites

There's 2 ways you can accomplish this.


You can use the Control.PointToClient() function, this will convert the screen coordinates that you specify into client coordinates.

For example if your PictureBox is placed at X=10, Y=10 inside the Form, and the mouse location is X=20, Y=20, myPictureBox.PointToClient(new Point(20, 20)) will return X=10, Y=10.


Another option is by computing the coordinates yourself. This is basically what PointToClient() does behind the scenes.

Point clientLocation = new Point(mousePosition.X - myPictureBox.Left, mousePosition.Y - myPictureBox.Top);


You can also use the the built-in mouse event handlers for controls (MouseDown, MouseMove, MouseUp, MouseLeave, MouseWheel). These events will automatically convert the mouse position to client coordinates, so you don't have to convert them yourself.

Edited by ta0soft

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!