如何将pictureBox恢复为默认设置?

编程入门 行业动态 更新时间:2024-10-27 14:33:38
本文介绍了如何将pictureBox恢复为默认设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

单击按钮时,如何将图片框的内容设置为默认设置?

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 . 如果您要处理图像,则很有可能不需要这种情况. 考虑替代方案: 如何从旧图纸中清除面板 [ ^ ].

—SA

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

更多推荐

如何将pictureBox恢复为默认设置?

本文发布于:2023-11-28 14:48:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   默认设置   pictureBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!