Tuesday 15 July 2014

Changing The Property Of An Object Using Variables? C#/Visual Studio -


OK, I have 100 buttons and I need to change the colors based on situations in the loop of time. The names are buttons 1, button 2, button 3, etc. The first time around the loop (repetition?) I have to edit the button 1, next time button 2, the third time button 3, etc. I thought I would just create a string equal to "button". The number of numbers around the loop and the colors change in that way.

string button number = "button" + i; where i = the number around the loop

when I button.Number.BackColor = Color.Red; I try to edit the color by using , then it will not give me this because this button does not look like a button, but like a string. How do I accomplish this? Thanks! (This is my first time too programming)

Consider using the controls. to find a control by name, and then you can change it to your property:

 for  (int i = 1; i  

No comments:

Post a Comment