Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hello friends,
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 reload it again then the ellipse drawn on PictureBox have bin disappear.
Any one can suggest remedy for this problem…
Thanks……..
Regards,
Pritesh Patel
Posted
Updated 15-May-11 5:21am
v3

You forgot to tell us what you are using. WPF? Windows Forms?

If it's Windows Forms, then the solution may be quite easy: You have drawn something and then minimize the form. When it is restored, all controls are told to redraw their contents and the old content is lost. You must simply override the controls OnPaint() method, which is called every time the control needs to redraw its content. Insert your own drawing code into the overridden method and everything will be as it should be,
 
Share this answer
 
v2
Comments
Pritesh Aryan 22-Mar-11 6:02am    
ya i understand but......is there any code sample?
[no name] 22-Mar-11 6:11am    
Try this:

http://windowsclient.net/articles/windowsformspainting.aspx

Of course, you must do this to the control you want to paint in and not for the form it self. But the principle remains the same.
Pritesh Aryan 22-Mar-11 6:14am    
ya i am trying......
[no name] 22-Mar-11 6:18am    
Good luck.
Sergey Alexandrovich Kryukov 22-Mar-11 11:42am    
You are right, my 5, but in this case paint box is not needed at all. Please see my Answer.
--SA
Do two things: 1) don't draw in picture box; 2) render directly on some control, the way CPD1802 offered; use overridden Control.OnPaint or event Paint, use Graphics object from the event argument. Also, it's good to use double buffering to avoid flicker.

To change graphics, change data used in rendering and use Control.Invalidate. To improve performance, use Invalidate with parameter (Rectangle or Region) which allows to invalidate just a part of the scene.

Picture box is completely redundant in this case, it's purpose is different. It's good to hold some static picture. If you want to draw in it, you can, but it is redundant as you can draw in any control without the middleman: less coding, memory consumption and better performance.

—SA
 
Share this answer
 
v4
Comments
Pritesh Aryan 23-Mar-11 2:45am    
ya but here CPD1802 means? Please elaborate....
Sergey Alexandrovich Kryukov 23-Mar-11 15:57pm    
It is elaborated in the rest of the sentence: Paint or OnPaint, alternatively. This is how you should render.
--SA
Sergey Alexandrovich Kryukov 27-Nov-11 17:44pm    
Gosh, this is a user ID of the member who gave you another advice.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900