The problem of the dynamic control array in VB.net is that the dynamic control array is easy to use in VB, but it is a bit confusing in VB.net.
In fact, it is also very simple, because VB.net and VB are different, let's take a look at how VB.net's dynamic control array is implemented.
1. define a common arraylist type variable in the form header.
Dim m_items as new arraylist
2.ProgramDynamically generate controls
While (A <B)
Dim lblcontrol as label = new label
Lblcontrol. Text = "hello"
Lblcontrol. Dock =... top
Lblcontrol. autosize = false.
....
Me. Controls. Add (lblcontrol) 'place dynamically generated controls in the corresponding area
'Note the following,
M_items.add (lblcontrol) 'put the label in the arraylist defined in the first step.
Addhandler label. Click, addressof lblcontrolarrayclick' defines the trigger function lblcontrolarrayclick for this group of dynamic controls.
End while
3. Define the trigger function of the click event of lblcontrolarrayclick. This is the key to pulling the event from different places than VB.
'Control array events
Private sub lblcontrolarrayclick (byval sender as object, byval e as eventargs)
Dim lbltext as string
Lbltext = ctype (sender, label). text' here, ctype restores the object that triggers the event to a label object,
'It's a bit like a set in Java. When you put it in and retrieve it, you need to shape it.
Msgbox ("the text of the dynamic control of the electric shock is:" & lbltext)
End sub
Well, it's that simple, the control array in VB.net.
If you want to define other trigger events for the control array, you only need to modify the corresponding trigger.