0

I need to make a loop and in this I need to change the properties of the buttons. What I have made:

while(count>=1){
P+count.BackColor = Color.Blue;
}

Result I want:

P1.BackColor = Color.Blue;
P2.BackColor = Color.Blue;
P3.BackColor = Color.Blue;
etc..

ps: the colors need to be specifically the colors form the database so I can't set them like the result.

Marvin Fischer
  • 2,552
  • 3
  • 23
  • 34

1 Answers1

0

You can get all controls in form and check if control is button or not. If control is a button then change background color. You can use code below,

foreach (Control control in this.Controls)
{
     if(control.GetType() == typeof(Button))
     {
            ((Button)control).BackColor = Color.Red;
     }
}
Onur Tekir
  • 220
  • 1
  • 3