Hi,
I am trying to add multiple PictureBoxes dynamically at runtime using a loop but have come a little stuck.
Here is the code I am working on:-
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.IO.Path.Combine(Application.StartupPath, "getPublicPhotos.xml"));
XmlNodeList photo = xDoc.GetElementsByTagName("photo");
for (int i = 0; i < photo.Count; ++ i)
{PictureBox[] pb = new PictureBox[i];
pb[i].Location = new Point(5, (i * 80) + 5);
pb[i].Size = new Size(75, 75);
pb[i].BorderStyle = BorderStyle.Fixed3D;
//pb.ImageLocation = "";
pb[i].Cursor = System.Windows.Forms.Cursors.Hand;
panel1.Controls.Add(pb[i]);
pb[i].BringToFront();
pb[i].Click += delegate(object s, EventArgs e2)
{
System.Diagnostics.Process.Start("");
};
}
When I try to run this I get an - IndexOutOfRangeException: Idex was outside the bounds of the array.
Any pointers in the right direction would be appreciated.
Kind regards..,
MT ;)