Click here to Skip to main content
15,889,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 28-May-11 21:44pm
v4
Comments
Kim Togo 28-May-11 12:51pm    
A default picture in PictureBox ?
thatraja 28-May-11 13:03pm    
Include the error message in your question always

1 solution

I would simply remove PictureBox from it's parent using Control.Remove. It should follow the lazy pattern.

C#
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


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
 
Share this answer
 
v2
Comments
Monjurul Habib 29-May-11 14:17pm    
cool my 5.
Sergey Alexandrovich Kryukov 29-May-11 14:36pm    
Thank you, Monjurul.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900