开发者

Preserve something I drew on a Form?

So ye开发者_如何学Cah,

Basically I drew something on a form using Graphics. Now if I move a window over the form the stuff I drew gets erased.

Is there a way to preserve the drawing?

(I'm using Windows.Forms)


Don't draw to the Form from outside the Paint event handler (which is what it sounds like you may be doing).

You can either redraw the contents every time in your Paint event handler, or you can paint once to an offscreen bitmap and then just display the bitmap in your Paint handler.

The code for both is almost identical, but to draw to an offscreen bitmap you need to set up a new bitmap for the Graphics context to draw into.

Here's an example which illustrates everything you need to do to use an offscreen bitmap to store the image. (And indeed, if you remove the offscreen-bitmap code from this example, the remaining code is how to draw in the Paint handler)


You need to draw in the Paint event of a control.


you have to repaint what you drawn in the Paint event handler.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜