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.
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.