An array of Controls on Main Form

  • Thread starter Thread starter Spurry Moses
  • Start date Start date
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);
}
 
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
 
Back
Top