VB.net control array Problems

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.