tags:

views:

43

answers:

3

Hello,

Question: How to check if Graphics object is usable.

My Problem: I create Graphics object from form and give it to "object X" for drawing, when form closes and "object X" tries to draw into Graphics object, GDI+ error occurs 0x80004005.

So i need to check if Graphics is drawable only having that Graphics object.

Any ideas?

A: 

When your form is closed you should inform your "object X" of this fact...

Otherwise the only way to know if a Graphics object is accessible is to call a small method on it like GetHdc (with the correct ReleaseHdc after if it succeed) and catch the error that may happens.

VirtualBlackFox
+1  A: 

The best way to draw objects is that handle the Paint event of the form. in the Paint() will you get access to Graphics which is drawable always. So you can use it without any problems.

Arseny
A: 

Nice idea with GetHdc and ReleaseHdc, VirtualBlackFox, lucks like it worked.

Good job.

Paklausk