Clear a Form

johnpc

Member
Joined
Oct 5, 2011
Messages
8
Programming Experience
10+
I have a form that uses a button to draw a line and a second button to draw a rectangle. I have a third button to clear the form but
can't find a code example to code the Clear button.
 
Clear your drawing cache and call Refresh, thus no drawing will be done from Paint event handler for this operation.
 
How do I do that with a button?
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click


'Clear your drawing cache and call Refresh,

'thus no drawing will be done from Paint event handler for this operation.


End Sub
 
You do painting from a controls Paint event handler, as such you must store information about what to draw (a cache if you will) whenever a repaint happens. So to "clear" you simply clear any information you have stored about what to draw, then call Refresh to force the control to redraw. Since your Paint handler now draws nothing this will effectively clear anything drawn before.
 
Back
Top