Reputation: 173
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?
Upvotes: 0
Views: 515
Reputation: 173
Nice idea with GetHdc and ReleaseHdc, VirtualBlackFox, lucks like it worked.
Good job.
Upvotes: 0
Reputation: 7361
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.
Upvotes: 1
Reputation: 17837
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.
Upvotes: 0