문제

I'm trying to create a slot machine, i have 3 empty pictureboxes and a image list with a bunch of different pictures in it, i use a random number generator to put images into the picturebox from the image list.

Now how do i compare to see if the three random pictures are matching?

picturebox1.image == picturebox2.image; 
//doesnt work because names aren't loaded to image property

picturebox1.imagelocation == picture2.imagelocation
//doesn't work because all images come from the same place.

I also can't try comparing the size or the extension because they are all the same I don't want to use multiple random number generators to select the random pictures and compare the different random numbers. Is there a trick i can do with the imagelist that i haven't thought of

도움이 되었습니까?

해결책

One option would be to use the Tag property... many classes have one, including Bitmap, Image, and PictureBox. You could assign a unique value to each Image.Tag...

var bmp = new Bitmap(1,1);
bmp.Tag = "uniqueTag";
pictureBox1.Image.Tag = bmp;   // pictureBox1.Image.Tag == "uniqueTag"

... then check for equality:

if (pictureBox1.Image.Tag == pictureBox2.Image.Tag)
{
    ...
}

다른 팁

When your random generator picks the index of the element you will pull from your image list, store the index in the picturebox.Tag or picturebox.Text, then compare if both Tag o Text are equal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top