In Visual Basic 6.0, control arrays could be used to manage controls on a form; they provided capabilities for sharing event handlers, iterating through groups of controls, and adding controls at run time.
In Visual Basic 2008, control arrays are no longer supported. Changes to the event model make control arrays unnecessary, and the .NET Framework provides the same capabilities for working with controls.
Sharing Event Handlers
In Visual Basic 6.0, control arrays could be used to specify a group of controls that shared a set of events. The controls had to be of the same type, and they had to have the same name.
Visual Basic 2008 allows any event handler to handle events from multiple controls, even controls with different names and of different types.
For example, you might add two Button controls (Button1 and Button2) and a CheckBox control (CheckBox1) to a form, and then create an event handler to handle the Click event for all three controls.
Private Sub MixedControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, CheckBox1.Click
Iterating Through Controls
Another feature of Visual Basic 6.0 control arrays was the ability to iterate through a group of controls using the Index property. For example, to clear the text of all TextBox controls in a control array, you could loop through the control array using the Index property as a loop variable.
Visual Basic 2008 controls do not have an Index property, but you can still iterate through the controls on a form or container using the Control..::.ControlCollection of the Control class.
In Visual Basic 6.0, controls in a single control array could be sited on different containers. For example, TextBox controls contained on two different Frame controls could be part of the same control array.
In Visual Basic 2008, the Controls collection only returns controls sited on a single container. You must iterate through the controls of each container control separately; this can be done using a recursive function.
Adding Controls at Run Time
In Visual Basic 6.0, controls could be added to a control array at run time using the Load statement. The controls had to be of the same type as the control array, and the control array had to be created at design time with at lest one element. After adding the control, the Visible property had to be set to True.
In Visual Basic 2008, controls are added at run time by using the New keyword in a Dim statement, then using the Add method for the container where you want to add the control.
Adding Event Handlers at Run Time
In Visual Basic 6.0, when you added a control to a control array at run time, the new controls events were automatically handled by the events for the control array.
In Visual Basic 2008, you need to define event handlers for controls added at run time. This is accomplished using the AddHandler statement.