-
Aug 24th, 2012, 07:56 AM
#1
Thread Starter
Lively Member
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?
-
Aug 24th, 2012, 08:11 AM
#2
Fanatic Member
Re: Position of a click on a picturebox
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;
}
-
Aug 24th, 2012, 05:20 PM
#3
Frenzied Member
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;
}
-
Aug 27th, 2012, 02:17 AM
#4
Thread Starter
Lively Member
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)
{
}
-
Aug 27th, 2012, 07:58 AM
#5
Frenzied Member
Re: Position of a click on a picturebox
when you write dot(.) just after e .you will get their Methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|