Mouse position

M

Mathieu Chavoutier

I want to make a tool to design (like paint).
So, I want to know the position of the mouse.

Cursor.Position.X gives me that information. But, when I draw a picture, it
is not at the good place
e.Graphics.DrawImage(newImage, new Rectangle(x, y, 32, 32));

I think it is because Cursor.Position.X is an absolute coordonate, and
DrawImage takes a relative coordonate.

So, how can I get the true position on the screen ?
 
S

Shakir Hussain

You have to convert to client co-ordinates using cusor position

testControl.PointToClient(Point (Cursor.Position.X ,Cursor.Position.Y));

Shak.
 
P

Patrick Steele [MVP]

I want to make a tool to design (like paint).
So, I want to know the position of the mouse.

Cursor.Position.X gives me that information. But, when I draw a picture, it
is not at the good place
e.Graphics.DrawImage(newImage, new Rectangle(x, y, 32, 32));

I think it is because Cursor.Position.X is an absolute coordonate, and
DrawImage takes a relative coordonate.

So, how can I get the true position on the screen ?

See the Control.PointToClient method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top