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