all groups > dotnet drawing api > february 2008 >
You're in the

dotnet drawing api

group:

Graphics.TextRenderingHint throw exception?


Graphics.TextRenderingHint throw exception? schneider
2/29/2008 1:06:06 PM
dotnet drawing api: Under some cases Graphics.TextRenderingHint and also Graphics.Save throws an
exception?

I can't seem to understand why. or what I'm doing wrong? and the error
message is useless.

Anyone know whats going on?

Thanks
Schneider

Re: Graphics.TextRenderingHint throw exception? Bob Powell [MVP]
2/29/2008 10:44:08 PM
Can you post an example of when this occurs?

--
--
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.


[quoted text, click to view]
Re: Graphics.TextRenderingHint throw exception? schneider
3/2/2008 5:55:54 PM
I can, just don't think it will help much:

Friend Function CalculateStringSize(ByVal canvas As Graphics) As Size

If canvas Is Nothing Then Throw New ArgumentNullException("canvas",
m_StringManager.GetString("nonullallowed",
System.Globalization.CultureInfo.CurrentUICulture))

If Font Is Nothing Then Throw New ArgumentNullException("font",
m_StringManager.GetString("nonullallowed",
System.Globalization.CultureInfo.CurrentUICulture))

'Dim gstate As GraphicsState = canvas.Save

Dim ct As TextRenderingHint = canvas.TextRenderingHint

canvas.TextRenderingHint = TextRenderingHint.ClearTypeGridFit

Dim sz As SizeF = canvas.MeasureString(Me.Text, Font)

sz.Width = sz.Width + CSng(sz.Width * 0.0125) + 1 '0.0125)

'canvas.Restore(gstate)

canvas.TextRenderingHint = ct

Dim s As New Size(CInt(sz.Width), CInt(sz.Height))

Return s

End Function



[quoted text, click to view]

Re: Graphics.TextRenderingHint throw exception? schneider
3/2/2008 5:57:47 PM
I should note the code usualy works. I must do something to graphics which
causes the problem.

Schneider


[quoted text, click to view]

Re: Graphics.TextRenderingHint throw exception? schneider
3/3/2008 9:40:46 AM
There is a lot of code and I can only reproduce it through a set of mouse
sequences.
I think maybe the graphics has been disposed, but can't be sure. Seems
strange the thow an error reading a property. Every property in graphics
says "Invalid parameter value". What parameter?

it craps out on:

Graphics.TextRenderingHint

or

Graphics.Save




[quoted text, click to view]

Re: Graphics.TextRenderingHint throw exception? schneider
3/3/2008 10:38:38 AM
Was think of writing some kind of generic wrapper to see if i am disposing
it too early...

Thanks, for the help, and I'm still waiting for you to publish a book on
..NET Drawing...

Thanks again,
Schneider


[quoted text, click to view]

Re: Graphics.TextRenderingHint throw exception? Bob Powell [MVP]
3/3/2008 12:38:12 PM
Some sort of compilable code that reproduces the problem will help to find
an answer.

--
--
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.


[quoted text, click to view]
Re: Graphics.TextRenderingHint throw exception? Bob Powell [MVP]
3/3/2008 4:19:20 PM
Disposing the graphics is a common problem. You'll need to check your code
carefully.

--
--
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.


[quoted text, click to view]
Re: Graphics.TextRenderingHint throw exception? Bob Powell [MVP]
3/3/2008 11:38:34 PM
It's been done too many times before. Chris Sell's and Mahesh Chands
books are great.

Anyway, I'm waaaay to busy working ;-)

--
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.





[quoted text, click to view]
Re: Graphics.TextRenderingHint throw exception? schneider
3/5/2008 12:42:03 AM
I still can't figure this out. Some how I invalidate the Graphics object.

Graphics.Save
Graphics.TextRenderHint
Graphics.MeasureString

all throw ArgumentException "Parameter is not valid.", and I'm not disposing
it.

Anyone have any ideas?

Thanks,

Schneider



[quoted text, click to view]

Re: Graphics.TextRenderingHint throw exception? schneider
3/6/2008 1:58:08 PM

I can't post all the code, there is just too much.
My initial assumtion was that a state on Graphics was change by me, which
caused this problem, and was hoping some one had experience with that
problem and how to fix it. I have seen this before when drawing text.

I think I have narrowed it down to the control resize event and the control
on_paint event.
I think your correct that the owner is disposing it before I am done
drawing.

If a new paint event is triggered, does it dispose the previous graphics
object right away? If so that is probably my problem...

Thanks,

Schneider




[quoted text, click to view]
Re: Graphics.TextRenderingHint throw exception? Bob Powell [MVP]
3/6/2008 6:29:37 PM
I bet you're caching one you've been given.

The owner will call dispose on it an you'll be left with a disposed
reference.

Don't cache Graphics objects.

Mind you, if you just posted all the code instead of feeding us snippets
and frustration we'd be able to see and point out the mistakes instead
of having to get the ideas through a process of divination...

--
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.





[quoted text, click to view]
AddThis Social Bookmark Button