更新时间:2022-06-07 23:01:31
我只是使用Control.Remove
从其父级中删除PictureBox
.它应该遵循惰性模式.
I would simply removePictureBox
from it''s parent usingControl.Remove
. It should follow the lazy pattern.
class MyForm : Form {
internal PictureBox {
get {
if (fMyPictureBox == null) {
fMyPictureBox = new PictureBox;
//whatever you need to set up it
pictureParent.Controls.Add(fMyPictureBox);
}
return fMyPictureBox;
}
} //PictureBox set
internal void ResetPicture() {
pictureParent.Controls.Remove(fMyPictureBox);
fMyPictureBox = null; //later will be re-created when needed
} //ResetPicture
//...
PictureBox fmyPictireBox;
Panel pictureParent;
} //class MyForm
此外,在大多数情况下,根本不需要PictureBox
.
如果您要处理图像,则很有可能不需要这种情况.
考虑替代方案:
如何从旧图纸中清除面板 [ ^ ].
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[^].