简体   繁体   中英

Picturebox background image list errors

With the following code:

for (int i = 0; i < Form1.pbName.Count; i++)
        {
            PictureBox catchcard = new PictureBox();
            catchcard.BackgroundImage = Form1.pbName[i].BackgroundImage;
            catchcard.BackgroundImageLayout = Form1.pbName[i].BackgroundImageLayout;
            catchcard.Name = Form1.pbName[i].Name;
            catchcard.Size = new Size(50, 50);
            if (!imagelist.Contains(catchcard.BackgroundImage))
            {
                images.Controls.Add(catchcard);
                imagelist.Add(catchcard.BackgroundImage);
            }
        }

I am unable to determine if I have already come across a certain background image before. The check comes up false even though I feed it several picturebox background images that are exactly the same.

I give it a card array called pbName, which holds all the pictureboxes representing cards in a deck, and then perform the check. In another area of the code I declare two pictureboxes with the exact same background image and feed them into pbName and then this code snippet. However, it doesn't detect that they have the same background image and is giving me grief. Is anything above incorrect?

May be try to define one PictureBox for one card

Before the loop:

PictureBox[] catchcardArray = new PictureBox[Form1.pb.Name.Count];

Inside the loop:

catchcardArray[i] = new PictureBox;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM