Well, just has a really weird “Parameter is not valid” ArgumentException exception being throw when trying to create a new TextBox.
e.g. Dim box As New TextBox()
Nothing weird about that you might think! The error was coming from down below, somewhere in the Font.GetHeight method.
Turned out that I was trying to be helpful in another part of code by Disposing of my Font objects
e.g.
Sub MakeBold(ByVal textbox1 As TextBox)
Dim f As New Font(textbox1.Font, FontStyle.Bold)
textbox1.Font.Dispose()
textbox1.Font = f
End Sub
Well, turns out thats not a good thing to do after all. I was only doing it because of the the Code Analysis warning, CA2000:DisposeObjectsBeforeLosingScope - which keeps telling me to dispose my Font objects!
I assume the reason is its trying to access the disposed font somewhere else down the line, maybe it caches fonts to help you out, I don’t know. Anyway, changing it to this fixes the problem:
Sub MakeBold(ByVal textbox1 As TextBox)
textbox1.Font = New Font(textbox1.Font, FontStyle.Bold)
End Sub
If anyone knows how to properly dispose the old font (if indeed you do need to) then let me know.
-
Pages
-
Recent Posts
-
Recent Comments
Categories
Blogroll
My Stuff
Useful Links
Archives
- November 2008
- August 2008
- July 2008
- May 2008
- April 2008
- March 2008
- January 2008
- November 2007
- October 2007
- September 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004