Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET graphics WinForm
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 22-Mar-11 0:13am
Edited 15-May-11 6:21am
ambarishtv10.5K
v3
Rate this: bad
good
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,
  Permalink  
v2
Comments
Pritesh Aryan at 22-Mar-11 6:02am
   
ya i understand but......is there any code sample?
CDP1802 at 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 at 22-Mar-11 6:14am
   
ya i am trying......
CDP1802 at 22-Mar-11 6:18am
   
Good luck.
SAKryukov at 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
Dalek Dave at 22-Mar-11 11:44am
   
Good Answer.
Abhinav S at 15-May-11 11:39am
   
Is the correct answer. 5. :)
Rate this: bad
good
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.
 
—SA
  Permalink  
v4
Comments
Pritesh Aryan at 23-Mar-11 2:45am
   
ya but here CPD1802 means? Please elaborate....
SAKryukov at 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
SAKryukov at 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)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 27 Nov 2011
Copyright © CodeProject, 1999-2014
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