How to check if image object is the same as one from resource?

后端 未结 3 2093
星月不相逢
星月不相逢 2020-11-29 13:19

So I\'m trying to create a simple program that just change the picture in a picture box when it\'s clicked. I\'m using just two pictures at the moment so my code for the pic

3条回答
  •  萌比男神i
    2020-11-29 13:55

    You need to use else if, because if the image is first, you set it to reitmi, then you check if it is reitmi, which it now is, and change it back to first. This ends up not appearing to change at all.

    if (pictureBox1.Image == Labirint.Properties.Resources.first)
        pictureBox1.Image = Labirint.Properties.Resources.reitmi;
    else if (pictureBox1.Image == Labirint.Properties.Resources.reitmi)
        pictureBox1.Image = Labirint.Properties.Resources.first;
    

提交回复
热议问题