本文介绍了如何将pictureBox恢复为默认设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
—SA
—SA
单击按钮时,如何将图片框的内容设置为默认设置?
when a button is clicked how can a picture box''s contents be set to default settings?
private void button4_Click(object sender, EventArgs e) { textBox1.Text = ""; pictureBox1.Container =empty; pictureBox2.Container =none; }这给出了一个错误!请问有人可以帮我吗? 错误消息是; 名称空"在当前上下文中不存在.
this gives an error! please can any one help me? error message is; The name ''empty'' does not exist in the current context.
推荐答案我只是使用Control.Remove从其父级中删除PictureBox.它应该遵循惰性模式. 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; //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[^].
更多推荐
如何将pictureBox恢复为默认设置?
发布评论