I have a flowLayoutPanel that has pictureBoxes in it. I add multiple PictureBoxes at run time like this:
while (flowLayoutPanel1.Controls.Count < 10)
{
flowLayoutPanel1.Controls.Add(new PictureBox());
}
I have a function that makes the "Image" property of each control equal to the "Image" values of Images in the LinkedList. The idea is to call the method when I want to add a new image to an Image Queue. When I pass a new Image to the function all the picture boxes in the FlowLayoutPanel display the last image in the linked list rather than the appropriate image in the LinkedList. I HAVE confirmed that LinkedList does in fact contain different images at each position. It is like all of the PictureBoxes in the FlowLayoutPanel are referencing the last one added.
internal void AddImage(ThermalImage thermalImage)
{
thermalImages.AddFirst(thermalImage);
while (thermalImages.Count > 10)
{
thermalImages.RemoveLast();
}
for (int i = 0; i < thermalImages.Count; i++)
{
PictureBox p = (PictureBox)flowLayoutPanel1.Controls[i];
p.Image = thermalImages.ElementAt(i).Image;
}
}
Is my initialization for populating the FlowLayoutPanel wrong? Is the way I am assigniung values to the PictureBox controls wrong? Why are all the PictureBoxes referencing the same Image?