Friday, August 6, 2010

How do I create an array of Buttons (or another control) in Microsoft Visual Studio?

For example, I am using Visual J#. If I go into the code, and add the array of buttons, nothing happens when I go into design view. How can I make it so that when I insert buttons, they go into an array? I am able to do this in regular Java, but I want to be able to design the form and still have them in an array.How do I create an array of Buttons (or another control) in Microsoft Visual Studio?
What you have to do is create a variable for each button and then pout those into an array. After you add them to the design view, if you right click on them there should be an option called 'add variable', or 'class wizard'. If you select that you can create a variable that points to the button, and then you can manually add those to the array. The only other alternative is to create an array of objects, and then initialize them through code instead of drawing them out in design view.How do I create an array of Buttons (or another control) in Microsoft Visual Studio?
system.windows.forms.button a[10];


for(n=0;n%26lt;10;n++)


{


a[n] = new system.windows.forms.button();


this.controls.add(a[n])


}

No comments:

Post a Comment