Font disposing

  • Thread starter Thread starter Danilo!
  • Start date Start date
D

Danilo!

Hi to everyone.

I would like to know what happens if I assign a new font, based from an
original font with some modified attributes, to a label (e.g.) font.
I better explain with an example:

Label1.Font = new Font(Label1.Font, FontStyle.Italic)

In this case, the new font created needs to be disposed, early or late? And
when is better to dispose it, in the close event of the parent form,
perhaps?

Thank you.
Danilo!
 
Generally, as long as you don't change the font a lot, GC will take care of
disposing of the font for you.

If you generate lots of fonts or use them in a paint routine then you should
ensure that you dispose of them correctly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top