I have been making game, where you get task to point every red/blue/green/yellow (random string color
) object (PictureBoxes) which are being spawned at a start of a programme. I wanted to give PictureBoxes on click events to add or substract point (if the color is wrong with the one in task), but I also wanted to make clicked PictureBox disappear, and I don't really know how to make goodshot
method know which PictureBox should disappear.
Goodshot method:
private void goodshot(object sender, EventArgs e) //showing score
{
score++;
scoring.Text = "Your score: " + score.ToString();
}
Badshot method:
private void badshot(object sender, EventArgs e) //showing score
{
score--;
scoring.Text = "Your score: " + score.ToString();
}
Creating PictureBoxes (there are else ifs for next colors (4 pictureboxes of every color)
PictureBox[] pb = new PictureBox[16];
for (int i = 0; i < 16; i++)
{
pb[i] = new PictureBox();
if (i < 4)
{
pb[i].ImageLocation = redpaths[rng.Next(0, redpaths.Count - 1)];
if(color == "red")
{
pb[i].MouseClick += new MouseEventHandler(goodshot);
}
else if(color != "red")
{
pb[i].MouseClick += new MouseEventHandler(badshot);
}
}