如何将pictureBox恢复为默认设置? [英] how can a pictureBox can be taken back to its default settings?

查看:118
本文介绍了如何将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恢复为默认设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆