Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have a menu item Clear which should clear the panel from all drawing.
There is no controls existing in this Panel only lines.

I thought it should be easy to clear the Panel from old drawings but it
isn't
I have tried with this code
graphics.Clear(drawingBox1.BackColor);
but the old drawing reback after clearing .

So how can I remove the old drawing and have the Panel as it is when I start
the program.
Posted
Comments
JOAT-MON 9-May-11 18:02pm    
What is your process for drawing in the panel? How you remove the drawing is in part relative to how you put the drawing in there.

1 solution

First of all, do you draw correctly?

You need to draw on the Panel (or any other Control) handling its event Paint or overriding OnPaint. You need to used the instance of the System.Drawing.Graphics you get from event arguments (in both cases). The call is repeated every time WM_PAINT message is dispatched. I won't happen until the control appears on screen again, after being masked by something else (maybe partially) or minimizing.

Now, what to do it your graphics changes? You simply change some data used in rendering and wait for new WM_PAINT. But how this message can be triggered programmatically (you need change to be immediately displayed)?

Very simple: you need to use System.Windows.Forms.Control.Invalidate! It will work.
To improve performance you can use Invalidate with parameters (Rectangle or Region); it will invalidate only the part of the scene, hopefully the part that has changed.

—SA
 
Share this answer
 

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