Hi guys, I'm new here so please help me. I wanted to create a memory game where in the user clicks on two images and matches them. However, in the middle of creating it I encountered a weird problem - whenever I set the "Visible" property of the PictureBox on "true" it doesn't show up but doing the opposite, setting it to "false" it works just fine. Here's the part of putting images in the PictureBox and setting its visibility to "false" and "true" on the "picture_Click" event.
.......
//assigning images in every picturebox in random and at the sametime setting its visibility on false
foreach (Control control in tlpHome.Controls)
{
PictureBox picBox = control as PictureBox;
if (picBox != null)
{
int randomNumber = random.Next(image.Count);
picBox.Image = image[randomNumber];
picBox.Visible = false;
image.RemoveAt(randomNumber);
}
}
//the event handler 'Click' of PictureBox. Should set the visibility of PictureBox on 'true' whenever it's clicked.
private void picture_Click(object sender, EventArgs e)
{
PictureBox clickedPicture = sender as PictureBox;
if (clickedPicture != null)
{
if (clickedPicture.Visible == true)
return;
clickedPicture.Visible = true;
}
}
Doesn't have any errors while building it. But it works fine if I reverse it which is the weird part - setting "picBox.Visible = true" and setting "clickedPicture.Visible == false" and clickedPicture.Visible = false"
Please help guys... Thanks!