So, I'm trying to create a simple program that just changes the image in the image window when clicked. Currently, I use only two photos, so my code for the click click event function looks like this:
private void pictureBox1_Click(object sender, EventArgs e)
{
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;
}
For some reason, the if statement does not work and the image does not change. What should I do?
Note: the source code contained an error with the second ifnegative effect of the first, if the condition works with the correction proposed by Cyral answer , but the addition elsedoes not fix the problem - step-by-step execution of the code with the help elsestill does not display matches for any image.
if (pictureBox1.Image == Labirint.Properties.Resources.first)
pictureBox1.Image = Labirint.Properties.Resources.reitmi;
if (pictureBox1.Image == Labirint.Properties.Resources.reitmi) // was missing else
pictureBox1.Image = Labirint.Properties.Resources.first;