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.
我正在尝试创建一个*,我有3个空的图片盒和一个包含一堆不同图片的图像列表,我使用随机数生成器将图像从图像列表放入图片框。
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
我也无法尝试比较大小或扩展,因为它们都是相同的我不想使用多个随机数生成器来选择随机图片并比较不同的随机数。有没有我可以用我没想过的图像列表做的技巧
2 个解决方案
#1
0
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
...
一种选择是使用Tag属性......许多类都有一个,包括Bitmap,Image和PictureBox。您可以为每个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)
{
...
}
#2
0
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.
当随机生成器选择要从图像列表中提取的元素的索引时,将索引存储在picturebox.Tag或picturebox.Text中,然后比较Tag o Text是否相等。
#1
0
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
...
一种选择是使用Tag属性......许多类都有一个,包括Bitmap,Image和PictureBox。您可以为每个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)
{
...
}
#2
0
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.
当随机生成器选择要从图像列表中提取的元素的索引时,将索引存储在picturebox.Tag或picturebox.Text中,然后比较Tag o Text是否相等。