With your code, you should not use
PictureBox
at all — it does nothing useful for you, nothing at all, only adds some pain in the… let's say, in the neck and steals some of your development time. What to do instead? Something a lot more simple. Please see my past answers:
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^],
capture the drawing on a panel[
^],
How to speed up my vb.net application?[
^].
And yes, you need to have some data model which may include, say, a Boolean flag named "clear". If it's "clear", just don't do any rendering. When you call
Control.Invalidate()
, your graphics will be refreshed, and your rendering method will be called not drawing anything.
—SA