You need 2 variables for the clicked Points, just make a counter and you've done:
int i = 0;
Point p1, p2;
void myPictureBox_MouseClick(object sender, MouseEventArgs e) {
if(i == 1) this.myPictureBox.MouseClick -= myPictureBox_MouseClick;
var point = new Point(e.X, e.Y);
MessageBox.Show(string.Format("You've selected a pixel with coordinates: {0}:{1}", point.X, point.Y));
if(i == 0) p1 = point;
else p2 = point;
i++;
}
//then use the two points p1,p2 for further processing.
Note that, if you want to implement in your way (using -=
to unregister the handler and so disable clicking on the PictureBox
), you should notice to disable the Start button right after clicking it and enable it back at property time like this:
private void startButton_Click(object sender, EventArgs e) {
//all the code you already had go first...
startButton.Enabled = false;
}
void myPictureBox_MouseClick(object sender, MouseEventArgs e) {
//...
if(i == 0) p1 = point;
else {
p2 = point;
startButton.Enabled = true;
}
i++;
}