I can guess from your post that you've had your hands dirty with VB6 and were a big fan of control arrays.
Any way, the VS.NET designer doesn't support control arrays! In case you're concerned with the performance benefit you could get with control arrays in VB6, there's no performance degradation because of the fact that each control has its independent existence in .NET.
One of the benefits of control arrays in VB6 is that you can write a single event handler to handle events of all members of the control array. You can acheive the same effect by writing an event handler and associating each control with that event in .NET.
In C#, for example, you can do it like this:
//
// Event handler to handle TextBox control's TextChanged event
//
private void textBox_TextChanged(object sender, EventArgs e) {
// Implementation...
}
// Code to wireup TextChanged event of three of the TextBox controls
// to the preceeding event handler. This code should go into the
// form's constructor.
this.textBox1.TextChanged += new EventHandler(textBox_TextChanged);
this.textBox2.TextChanged += new EventHandler(textBox_TextChanged);
this.textBox3.TextChanged += new EventHandler(textBox_TextChanged);
In the event handler, you can identify which control fired the event like this:
...
if (sender.Equals(textBox1)) {
// textBox1 fired the event.
}
else if (sender.Equals(textBox2)) {
// textBox2 fired the event.
}
else if (sender.Equals(textBox3)) {
// textBox3 fired the event.
}
This way you get all the benefits of control arrays.
If you wish, you can create control arrays in code like this:
...
TextBox[] textBoxes = new TextBox[] {new TextBox(),
new TextBox(),
new TextBox()};
Controls created in this way, however, don't show up on the form until you add them to the Controls collection of the Form. One way of doing this is:
...
this.Controls.AddRange(textBoxes);
I hope this helps.
ejan
|