Code Mirror

Code Mirror

  • NA
  • 2
  • 3.4k

only last dynamically created picturebox is accessible

Sep 18 2013 7:00 AM
i m creating a win form application in which i have a tabcontrol1
and at run time created tabpage and picturebox
on a button click i make new tab page and picture box
and add them to the tabcontrol1.
 
now i can change image of only last created picture box...
and when i try to change the image of any picture box except the last one, i am not able to do that
 
this is the code example
 
button1 creates new tabpage and picturebox
private void button1_Click(object sender, EventArgs e)
        {
            TabPage tpgallery = new TabPage();           
            tpgallery.Name = "tpgallery";
            tpgallery.Text = "  Gallery  ";            
 
            tabControl1.TabPages.Add(tpgallery);           
 
            picturebox1 = new PictureBox();           
 
            picturebox1.Name = "picturebox1name";           
            picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo1;
 
            tpgallery.Controls.Add(picturebox1);          
        }
 
button2 changes image of picturebox
 
private void button2_Click(object sender, EventArgs e)
        {
 
            picturebox1.Image = WindowsFormsApplication7.Properties.Resources.logo2;
 
        }

Answers (1)