Hello I'm making 10x10 cube with panels and the panels needs to change color when you click X times the panel but the code is so large, Is there another way for the code not to be so long?
This is my code:
int cont1 = 0, cont2 = 0, cont3 = 0, cont4 = 0, cont5 = 0, cont6 = 0, cont7 = 0, cont8 = 0, cont9 = 0, cont10 = 0;
then the event to change de color(All of my Panels have the same code but difference is "cont" and panel name):
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
cont1++;
if (cont1 <= 5)
{
panel1.BackColor = Color.SlateBlue;
}
if (cont1 >=5)
{
panel1.BackColor = Color.Cyan;
}
if (cont1 >= 10)
{
panel1.BackColor = Color.Lime;
}
if (cont1 >= 15)
{
panel1.BackColor = Color.Yellow;
}
if (cont1 >= 20)
{
panel1.BackColor = Color.Red;
}
}
//other panel
private void panel2_MouseClick(object sender, MouseEventArgs e)
{
cont2++;
if (cont2 <= 5)
{
panel2.BackColor = Color.SlateBlue;
}
if (cont2 >= 5)
{
panel2.BackColor = Color.Cyan;
}
if (cont2 >= 10)
{
panel2.BackColor = Color.Lime;
}
if (cont2 >= 15)
{
panel2.BackColor = Color.Yellow;
}
if (cont2 >= 20)
{
panel2.BackColor = Color.Red;
}
}
note: Each panel changes its color, not all at the same time Actually work with 4x4 but 10x10 is large for me