An array of Controls on Main Form

S

Spurry Moses

Hi,

I want to create an array of combo boxes on my form.

The only problem is that I don't want to place 3 seperate combo boxes on
the form if I can avoid it. I'd just like to create an array and
dynamically create them. For example, like the code (that uses Radio
Buttons) below.

Can I do this and be able to position them on the form as well (even if
just in code). I would have to edit code that says "Form Designer Code -
Do not edit"... it all seems like it's not really feasible.


System.Windows.Forms.RadioButton [] radioButtons = new
System.Windows.Forms.RadioButton[3];

for(int i=0; i<3; ++i)
{
radioButtons = new RadioButton();
radioButtons.Text = stringArray;
radioButtons.Location = new System.Drawing.Point(10, 10+i*20);
this.Controls.Add(radioButtons);
}
 
M

Maqsood Ahmed

Hello,
You don't need to change the InitializeComponent method code. You can
write this code in your form's constructor. you can also use
this.Controls.AddRange(array) to add many controls at once.

HTH. Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top