Re: Graphics.TextRenderingHint throw exception?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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




"Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:u0$Oo%236fIHA.2000@xxxxxxxxxxxxxxxxxxxxxxx
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.





schneider wrote:
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



"schneider" <eschneider@xxxxxxxxxxxxx> wrote in message
news:OJ1JATweIHA.3724@xxxxxxxxxxxxxxxxxxxxxxx
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



.



Relevant Pages

  • Re: Scrolling question
    ... There's no function to generate the sine waves. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... >>> protected override void Dispose(bool disposing) ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Graphics.TextRenderingHint throw exception?
    ... Was think of writing some kind of generic wrapper to see if i am disposing ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: A GDI+ problem
    ... followed by the graphics you've defined so it flickers. ... /// Summary description for Form1. ... // Required for Windows Form Designer support // ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Resizing Images
    ... The most direct benefit is that since various calls to the Graphics class include overloads that can use a Size instance, the code is simpler, since you're dealing with one value instead of two. ... IDisposable objects. ... as disposing objects in the wrong order (such as disposing a Bitmap ... Bitmap instance, as you've done here). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Resource usage
    ... You should most definitely be disposing of the brush, ... be disposing of your canvas reference (to the Graphics object), ...
    (microsoft.public.dotnet.languages.csharp)