private void p01_Click(object sender, EventArgs e)
{
if (p01.Image == pmiss.Image)
{
score++;
makeMoleVisable(1, phit);
}
else
{
score--;
molesmissed++;
}
}
private void p02_Click(object sender, EventArgs e)
{
if (p02.Visible)
{
if (p02.Image == pmiss.Image)
{
score++;
p02.Image = phit.Image;
}
else
{
score--;
molesmissed++;
}
}
}
Hello I Have 36 of these picturebox click events. I want to use just one click event for all 36 picture boxes. Additionally all click events do the same thing, the code is just slightly different on the first one. Thnaks
Just go to the events property of each picture and set to p02_Click
or use your own custom name.
If you have all the picture boxes in one panel, you could try:
foreach (Control p in mypanel.ControlCollection)
{
p = p as PictureBox;
p.Click += (p01_Click);
}
You can also test to see if it's pictureBox1 by setting a Tag
property for p01
and checking that property in code.