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;
}
FroglegPosted Sep 18, 2013, 8:21 AM
public partial class Form1 : Form
{
PictureBox[] picturebox1 = new PictureBox[3];//array of three pictureBoxes
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
disablebutts(false);
}
public void disablebutts(bool cat)// disable buttons so user cannot click before pictureboxes are created
{
button2.Enabled = cat;
button3.Enabled = cat;
button4.Enabled = cat;
}
private void button1_Click(object sender, EventArgs e)
{
disablebutts(true);
TabPage tpgallery = new TabPage();
tpgallery.Name = "tpgallery";
tpgallery.Text = " Gallery ";
tabControl1.TabPages.Add(tpgallery);
int lft = 0;
for (int i = 0; i < 3; i++)//create the pictureBoxes
{
picturebox1[i] = new PictureBox();
picturebox1[i].Name = ("picturebox" + i.ToString());
picturebox1[i].SizeMode = PictureBoxSizeMode.AutoSize;
picturebox1[i].Image = Properties.Resources.logo1;
picturebox1[i].BorderStyle = BorderStyle.FixedSingle;
picturebox1[i].Left = lft;//set boxes 200 apart
//if (i == 2)//use to place elsewhere
//{
// tabPage1.Controls.Add(picturebox1[i]);
//}
//else
//{
// tpgallery.Controls.Add(picturebox1[i]);
//}
tpgallery.Controls.Add(picturebox1[i]);
lft += 200;
}
}
private void button2_Click(object sender, EventArgs e)
{
picturebox1[0].Image = Properties.Resources.logo2;//change image on first picturebox
picturebox1[0].Refresh();
}
private void button3_Click(object sender, EventArgs e)
{
picturebox1[1].Image = Properties.Resources.logo2;//change image on second picturebox
picturebox1[1].Refresh();
}
private void button4_Click(object sender, EventArgs e)
{
picturebox1[2].Image = Properties.Resources.logo2;//change image on third picturebox
picturebox1[2].Refresh();
}
}