Grab the coordinates of the mouse position by clicking

Asked

Viewed 3,261 times

0

I have to trace a line with starting point and ending point,I can do this line if I provide these coordinates by keyboard, but I want to do this by mouse click,the first would be the starting point and the second the end and with the data the algorithm would trace the line,?

It is an application in Windows Forms in C#

  • You want the coordinate according to the monitor or the component that is clicked?

1 answer

1

If you want the coordinates according to the component that is clicked

Point coordenadas = control.PointToClient(Cursor.Position);

If it is according to the position on the monitor

Point coordenadas = Cursor.Position;

Point is a class that contains the properties X (horizontal position) and Y (upright).

  • With this code I just show the coordinates when moving the mouse, I want to store the coordinate of the point I click

  • I don’t understand your problem. The variable coordenadas is not storing the location that was clicked?

  • @Guilhermebueno You put the code in the event of click? Give me more details about your problem...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.