In C# forms I've created a function that will, once invoked, create a picturebox with desired image, size and location:

```
private void NewPic(string nName, int locX, int locY, int SizX, int SizY, Image Img)
{
    PictureBox Pic = new PictureBox();
    Pic.Name = nName; Pic.Image = Img;
    Pic.BackColor = Color.Transparent;
    Pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    Pic.Size = new System.Drawing.Size(SizX, SizY);
    Pic.Location = new System.Drawing.Point(locX, locY);
    Controls.Add(Pic);
    Pic.Click += new EventHandler(Pic_Click);
}

```

Now when I need a picture I just do this:

```
NewPic("FIRE", 32, 100, 120, 120, Properties.Resources.Image);

```

The problem is, in the click event, when I click on picturebox I want it to change its background image, but, if I click some other picturebox I want the last one to reset it self:

```
private void Pic_Click(object sender, System.EventArgs e)
{
    PictureBox pb = (PictureBox)sender;
    switch (pb.Name)
    {
        case "1": 
            pb.BackgroundImage = Properties.Resources.OtherImg; //creates the background
            pb.BackgroundImageLayout = ImageLayout.Stretch;
                //INSERT CODE HERE: to remove from other if it has
            break;
        case "2":
            pb.BackgroundImage = Properties.Resources.OtherImg; //creates the background
            pb.BackgroundImageLayout = ImageLayout.Stretch;
                //INSERT CODE HERE: to remove from other if it has
            break;
        }
     }

```

I need code that can be applied to multiple pictureboxes/objects, not just the two