Click here to Skip to main content
11,929,675 members (55,740 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET graphics
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…
Pritesh Patel
Posted 22-Mar-11 0:13am
Edited 15-May-11 6:21am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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,
Pritesh Aryan 22-Mar-11 6:02am
ya i understand there any code sample?
CDP1802 22-Mar-11 6:11am
Try this:

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......
CDP1802 22-Mar-11 6:18am
Good luck.
SAKryukov 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.
Dalek Dave 22-Mar-11 11:44am
Good Answer.
Abhinav S 15-May-11 11:39am
Is the correct answer. 5. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 27 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100