I need to make a simple matching game. With this matching game I need to show an image when I click on it. Before the click event there's only a color shown. I already have a method which assigns images to the labels like so:
private void imgToLbl()
{
foreach (Control ctrl in tableLayoutPanel1.Controls)
{
Label imgLbl = ctrl as Label;
if (imgLbl != null)
{
int rndNum = rndImage.Next(0, files.Count);
imgLbl.Image = files[rndNum];
lbls.Add(imgLbl);
imags.Add(imgLbl.Image);
ints.Add(rndNum);
files.RemoveAt(rndNum);
}
}
}
I also thought that I had to make 2 other lists for the final assigned images and labels. So I can assign them again in the click event using the ints list as index indicators. I already have a part of my click event:
private void label_click(object sender, EventArgs e)
{
Label clickLbl = sender as Label;
if (clickLbl != null)
{
}
}
My thoughts are that I, somehow, have to check te index of clickLbl in the label list. But I don't know how. I can be completely wrong here but I would like to hear a good method for this. Can someone please help me out? I`m really clueless at the moment.
these are the steps it should go through:
When the application starts the labels shouldn't have images
When the user clicks the label will show it's image which was assigned in the imgToLbl() method
The image is now visible
NOTE:
I can not use pictureboxes instead of the labels. We HAVE to use labels. otherwise I wouldn't be asking this question