Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Drawing.Font.GetHeight() Exception

Status
Not open for further replies.

JurkMonkey

Programmer
Nov 23, 2004
1,731
CA
Code:
	"   at System.Drawing.Font.GetHeight(Graphics graphics)\r\n   at System.Drawing.Font.GetHeight()\r\n   at System.Drawing.Font.get_Height()\r\n   at System.Windows.Forms.Control.get_FontHeight()\r\n   at System.Windows.Forms.ComboBox.get_PreferredHeight()\r\n   at System.Windows.Forms.ComboBox.get_DefaultSize()\r\n   at System.Windows.Forms.Control..ctor()\r\n   at System.Windows.Forms.ListControl..ctor()\r\n   at System.Windows.Forms.ComboBox..ctor()\r\n   at

So I was fighting with this little error for a while. Nobody had a good answer for that. Someone wrote about a font being corrupt after installing office 2007 but that didn't help me either.

What ended up happening is this:

I have a drawing class that manipulates an image using GDI+
In order to draw text I passed in a Font from my main control to draw with. After closing my image I Disposed of that font. Turns out I was disposing the reference to the font that I passed in so now the base control's font was disposed.

When I tried to create a new control on my base control I started getting an error in InitializeComponent() - specifically while trying to create a ComboBox. So now I just orphan the reference to that font ( = null ) rather than dispose of it. The base class will dispose of it correctly when it's ready.

Just thought it's handy for anyone else who runs into this one.
 
> I was disposing the reference to the font that I passed in <

I dont work with C# ... only when I have to.
You said that you passed the reference. You mean that you passed a pointer... right ?
 
Apparently when you pass something into a method it acts on the low level like a pointer unless you specify byval in which, a copy of that object will be passed in.
 
Yes, In VB the "local copy" is defined as ByVal, whereas the memory location.. as ByRef (pointer in C)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top