Position of a click on a picturebox
If I double click my picturebox in the design screen, I get a click event method in my code:
Code:
private void PictureBox1_Click(object sender, EventArgs e)
{
}
I know very little of the event syntax and class design, so I don't know how to get information from the event in question. I would like to know the coordinates where my mouse clicked the picturebox. Something like this:
Code:
private void PictureBox1_Click(object sender, EventArgs e)
{
int x = e.X;
int y = e.Y;
}
I know this won't work. But how should this be done?
Re: Position of a click on a picturebox
Quote:
Originally Posted by
drdress
If I double click my picturebox in the design screen, I get a click event method in my code:
Code:
private void PictureBox1_Click(object sender, EventArgs e)
{
}
I know very little of the event syntax and class design, so I don't know how to get information from the event in question. I would like to know the coordinates where my mouse clicked the picturebox. Something like this:
Code:
private void PictureBox1_Click(object sender, EventArgs e)
{
int x = e.X;
int y = e.Y;
}
I know this won't work. But how should this be done?
Most events will have 'EventArgs' that contains information regarding the event. As you can see below the MouseClick event for a picture box has 'MouseEventArgs' which contains the coordinates of where you clicked.
Code:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int xCoordinate = e.X;
int yCoordinate = e.Y;
}
Re: Position of a click on a picturebox
really MouseEventArgs object have x and y property which specify the coordinates of where your mouse is cliked .
Code:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int xCoordinate = e.X;
int yCoordinate = e.Y;
}
Re: Position of a click on a picturebox
Well, as I wrote when I double click the picturebox (called pbProfile) I get the method:
Code:
private void PictureBox1_Click(object sender, EventArgs e)
{
}
This does not contain an event arg called MouseEventArgs, but only EventArgs which doesn't have an x- and y-coordinate. So how do I get the method you wrote:
Code:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
}
Re: Position of a click on a picturebox
when you write dot(.) just after e .you will get their Methods.