Creating Array of Buttons that already exist
Hi guys, I have 48 buttons on my form, the problem is; how can I make it as one. I mean, how can I create an array of buttons just like in VB 6.0
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Nov 6, 2008, 4:13 AM
In .NET you have to create the array manually.
This is tedious unless your buttons have similar names such as button1, button2, .... , button48 and they're all in the same container such as the form itself.
In that case you can do (.NET 2.0 or later):
Button[] buttons = new Button[48];
for(int i = 0; i < 48; i++)
{
buttons[i] = (Button)this.Controls["button" + (i + 1).ToString()];
}