I made some insertions into your code to help you get the idea of
what you have to do. See my explanation at the end.
private void UserControl1_Load(object sender, EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"Items\XMLActiveX.xml");
XmlNodeList xnl = xdoc.SelectSingleNode("imageroot").ChildNodes;
label1.Text = String.Empty;
foreach (XmlNode xNode in xnl)
{
XmlElement xElem = (XmlElement)xNode;
XmlNodeList name = xElem.GetElementsByTagName("name");
XmlNodeList x = xElem.GetElementsByTagName("x");
XmlNodeList y = xElem.GetElementsByTagName("y");
XmlNodeList path = xElem.GetElementsByTagName("path");
}
for (int i = 0; i < name.Count; i++)
{
label1.Text += "Image Name: " + name[i].InnerText + "\n";
label1.Size += new System.Drawing.Size(100, 10);
x1 = Convert.ToInt32(x[i].InnerText);
y1 = Convert.ToInt32(y[i].InnerText);
label1.Location = new Point(x1, y1);
PictureBox pb = new PictureBox();
Image img = Image.FromFile(path[i]);
pb.BackgroundImage = img;
pb.Width = img.Width;
pb.Height = img.Height;
}
}
}
If you want to display the image along with it's name I would suggest that you implement that as a separate user control. It would make your code more structured. Also spreading of the different values into separate arrays is not a good idea.
Make a small class that contains the data you're picking from the XML and you can then use XmlSerialization to extract the data.
You also need to think about screen realestate and how to best use it. If you cant control or know how big pictures can get it's better to go with a fixed size PictureBox and set it to Stretch or Zoom.
If need to add dynamically created controls to a container. That can be your user control itself or a container you have on your user control like a panel for instance.
Instead of using PictureBox's Image property to set the image I used BackgroundImage because it lets you set the ImageLayout in case you need to automatically stretch or zoom.
Regards,
Manfred