I have a form in which several buttons are added at runtime via a ‘for’ method
public Form()
{
for (int i = 0 ... )
Button b = new Button()
b.text = (string) i ;
etc..
etc..
}
. now i wish to change the text property of the buttons on a certain event. How can this be accomplished? I have tried a few things but none worked.. since the buttons variables are inside the method , they are not available outside.
Thanks
The variables aren’t important (although you could store them in a single
List<T>field if it made things easier). The normal way to do this is to look through theControlscollection (recursively, if necessary).The above assumes all the buttons were added to the same parent control; if that isn’t the case, then walk recursively: