I would simply remove
PictureBox
from it's parent using
Control.Remove
. It should follow the lazy pattern.
class MyForm : Form {
internal PictureBox {
get {
if (fMyPictureBox == null) {
fMyPictureBox = new PictureBox;
pictureParent.Controls.Add(fMyPictureBox);
}
return fMyPictureBox;
}
}
internal void ResetPicture() {
pictureParent.Controls.Remove(fMyPictureBox);
fMyPictureBox = null;
}
PictureBox fmyPictireBox;
Panel pictureParent;
}
Besides, in most cases
PictureBox
is not needed at all.
If you're manipulating the image, chances are, you don't need it in your case.
Consider the alternative:
How do I clear a panel from old drawing[
^].
—SA