0

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?

Eric Snyder
  • 1,816
  • 3
  • 22
  • 46
  • 1
    Where in the code are you calling : AddImage(ThermalImage thermalImage) – jdweng Feb 15 '19 at 17:35
  • 2
    Works for me...show us more code. – Idle_Mind Feb 15 '19 at 17:49
  • Thank you for looking at this. I solved the issue. It had something to do with the FLIR ThermalImage object. If I saved the ThermalImage object to disk and then reloaded it to a new ThermalImageFile object then it works fine. Thank you for confirming that the logic above is good. That we the confirmation I needed to get it figured out. – Eric Snyder Feb 15 '19 at 20:52

0 Answers0