Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read picture box mouse coordinates on click

I have a Picture Box with a picture loaded and I want to read the location (as in x,y inside the Picture Box) when I click the image; is this possible ? Even more, can i read these coordinates (Points) when i mouse over ?

I know i have to use the events given (Mouse Click and Mouse Over) but don't know how to read the coordinates where the mouse pointer happens to be.

like image 870
Razvan Avatar asked Aug 04 '13 07:08

Razvan


1 Answers

Though other answers are correct let me add my point to it. You've pointed that you need to hook up MouseClick or MouseOver events for this purpose. Actually that is no need to hook those events to get Coordinates, you can get the Coordinates in just Click event itself.

private void pictureBox1_Click(object sender, EventArgs e)
{
    MouseEventArgs me = (MouseEventArgs)e;
    Point coordinates = me.Location;
}

The above code works since Click event's e argument wraps MouseEventArgs you can just cast it and make use of it.

like image 115
Sriram Sakthivel Avatar answered Oct 23 '22 02:10

Sriram Sakthivel