PC Review


Reply
Thread Tools Rate Thread

how to dispose of a Pen object

 
 
Tony Johansson
Guest
Posts: n/a
 
      17th Apr 2011
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
object dispose laputa Microsoft Dot NET Framework 2 19th Jan 2009 08:46 AM
.net object dispose laputa Microsoft Dot NET 4 18th Jan 2009 11:43 AM
Dispose GDI+ object #Hai Microsoft Dot NET Framework 3 9th Jul 2003 08:21 PM
Dispose GDI+ object #Hai Microsoft Dot NET 3 9th Jul 2003 08:21 PM
Dispose GDI+ object #Hai Microsoft C# .NET 3 9th Jul 2003 08:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:56 PM.