bikt
bikt

Reputation: 173

C# Graphics object

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

Answers (3)

bikt
bikt

Reputation: 173

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

Good job.

Upvotes: 0

Arseny
Arseny

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

Julien Roncaglia
Julien Roncaglia

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

Related Questions