You pass either a
reference to a variable, or the
value in a variable from one method/context/object to another. Whether a reference is passed, or a value, will depend on the Type of the object that is passed, reference, or value.
There is a special syntax for indicating passing a variable by reference in a way that its value(s) can be changed by the object it is passed to ('out, 'ref), the default case being that the Value Type contents of a variable passed by reference will be copied.
The first thing for you to realize is that when you declare a variable inside a Method, that variable "exists" only
inside that Method; technically, this is expressed as saying the variable goes
out of scope when the Method terminates. The remedy is to declare the variables at the level (the scope of) the Form.
Second, you are declaring a new PaintEventHandler every time you get a 'MouseUp: unlike declaring a variable this will create a new Event Object and add it to the Invocation List of the EventHandler, so you are going to end-up with a very bloated EventHandler ! The remedy is to assign the EventHandler
once to the Paint Event, either at design-time, or, at run-time in the Form Load Event.
So, the 'point1, and 'point2 variables you declare and set the values of in the 'MouseClick and 'MouseUp EventHandlers can never be used outside those Methods.
Finally, your use of 'MouseClick, rather than 'MouseDown is a mistake; why the creators of WinForms made the MouseClick not register its location in the same way that MouseDown does ... in the case where you click, then drag, then mouse-up ... you better ask Microsoft about that.
Try this:
private void Form1_Load(object sender, EventArgs e)
{
this.Paint += Form1_Paint;
}
private Point[] twoPoints = new Point[2];
private Pen pen = new Pen(Color.Black, 3);
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLines(pen, twoPoints);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
twoPoints[0] = e.Location;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
twoPoints[1] = e.Location;
Invalidate();
}