mouse coordinats in game-window

Started by
1 comment, last by ta0soft 10 years, 1 month ago

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?

Advertisement

What language are you using?

Edit-

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

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.

This topic is closed to new replies.

Advertisement