开发者

Picture box lose drawing after reloading

I currently working with PictureBox and facing one problem.

First, I have drawn one ellipse on the PictureBox.

It draws nicely on the picture box.

But when I minimizing the form and reloa开发者_运维问答d it again then the ellipse drawn on PictureBox have bin disappear.

Any one can suggest remedy for this problem…

Thanks……..

Regards, Pritesh Patel


The Graphics object in .NET is not retained-mode, so you need to draw your ellipse within the Paint event for the object, in your case the picture box.


As Martin suggests you should redraw the picture whenever the form is drawn.

If this is undesirable or impossible then the only other option is to draw a picture that you display in the picture box.

You can create a Graphics object from an Image object using Graphics.FromImage. Using this object you can draw your image as you want and when you are done you can assign that image to the Picture box' Image property. This image will be retained as long as your form object lives.


I did face the same problem as you do with screen redrawing. What I did to resolve this was to store all the user actions into a List, so each time the paint event is called all the actions recorded on to the list is replayed. In your case all the x,y coords will be stored up to the point the user releases the mouse.

Though this seems a hard at first but you will appreciate the flexibility it offers while implementing Undo and Redo.

Here is a link which contains code sample to get this done. http://social.msdn.microsoft.com/Forums/pl-PL/wpf/thread/048ae883-f3e2-4ddc-bb89-fd72f00dd755


Use paint event of your PictureBox

from MSDN:

The Paint event is raised when the control is redrawn. It passes an instance of PaintEventArgs to the method(s) that handles the Paint event.


You need to call the Draw method in paint event.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜