开发者

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?


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.


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.


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

Good job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜