Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,I want clear all line in windows form that drawn with graphic method.
Here this is the code :
C++
Graphics^ pg = CreateGraphics();
Pen^ pen1 = gcnew Pen(Color::Red);
pg->DrawLine(pen1, 100, 100, 200, 200);


I try do it by Graphic.clear() but it wasn't successful.
Please help me!
Posted

First of all, you have to do all graphics rendering in your handler of the event Paint, or overridden method Control.Paint. The actual call to your handler is done when the control or its part is invalidated. It happens in different situation, but you can explicitly do it, for the whole scene or its part, to reflect last changes in your data: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v=vs.110%29.aspx[^].

Please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

Let's say, you have a Boolean member of your control's class, such as makeEmpty. If you use it in your handler, you can wrote if (makeEmpty) doSomeRendering(graphics); then you control if you rendering (or part of your rendering) is done or not after next invalidation. To "clear" the view, you can assign it to false and call Invalidate, then rendering will be refreshed without your lines.

—SA
 
Share this answer
 
Comments
TheCaptain10 31-Jul-15 9:41am    
Thank you.
Sergey Alexandrovich Kryukov 31-Jul-15 9:46am    
You are welcome. Will you accept the answer formally?
—SA
TheCaptain10 31-Jul-15 9:52am    
Yes,it worked.
Sergey Alexandrovich Kryukov 31-Jul-15 9:57am    
Great. No doubt about it.
—SA
TheCaptain10 31-Jul-15 10:03am    
Of course.
Can I be in touch with you?
I want learn from you.
You can call Graphics.Clear with background color or call this.Invalidate() method to erase it.
 
Share this answer
 
Comments
TheCaptain10 31-Jul-15 9:41am    
Thank you.

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