المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Font Disposal



C# Programming
03-31-2009, 03:40 PM
I have the following class structure - as you can see the nested class has an additional Font that needs disposing.

I'm not too hot on Disposal techniques (the laziness of the managed world!), is the method I've used sufficient and 'safe'?public class MyClass : IDisposable
{
private MyNestedForm myNestedForm;

public MyClass()
{
myNestedForm = new MyNestedForm();
}

public Font XYZFont
{
set { myNestedForm.XYZFont = value; }
}

public void Dispose()
{
myNestedForm.Dispose();
}

internal class MyNestedForm : Form
{
private Font xyzFont;

public Font XYZFont
{
get
{
if(xyzFont==null)
return Control.DefaultFont;
else
return xyzFont;
}
set { xyzFont = value; }
}

protected override void Dispose(bool disposing)
{
if (xyzFont != null)
xyzFont.Dispose();
base.Dispose(disposing);
}
}
}

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn (http://www.codeproject.com/script/Membership/Profiles.aspx?mid=648011))
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia (http://uncyclopedia.org/wiki/.NET))