Hello!
Here I just draw a line from point start to point end.
In this program I have done dispose of the Pen object which is correct.
Now to my question. Assume I use the Pen object like this instead
g.DrawLine(new Pen(Color.Blue, 1), start, end);
and don't keep any reference to the pen object to do dispose on.
What will happen with the pen object that I have done new on will it be
disposed automatically ?
private void pnlDiagram_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
//Move origo down to the left corner
g.TranslateTransform(pnlDiagram.Width * 1/10, pnlDiagram.Height *
9/10);
Pen pen = new Pen(Color.Blue, 1);
Point start = new Point(0, 0);
Point end = new Point(0, -pnlDiagram.Height +
(int)(2*0.1*pnlDiagram.Height));
g.DrawLine(pen, start, end);
pen.Dispose();
}
//Tony
|