Create a control array in Visual Basic. NET

Source: Internet
Author: User
Tags arrays
Create a control array in Visual Basic. NET
Introduction
Arrays provide a convenient way for control groups that use shared public functions. For example, a control group can be used to display related data or provide related operations when clicked. Visual Basic. NET does not support the creation of control arrays, but you can use programming to copy all functions of control arrays. This document describes how to create a simple component for copying control arrays.
Some functions of the control array are as follows:
You can use indexes to access a set of controls with the same name. You can retrieve and set properties by number and traverse all controls in the array. The typical syntax of this operation is as follows:
'Visual Basic pseudocode
MyControl (myIndex). MyProperty = myValue
MyControl (myIndex + 1). MyMethod
Use a single event handler to process events of multiple controls and retrieve and use the indexes of these events, as shown in the following example:
'Visual Basic pseudocode
Private Sub MyControl_Click (sender as Object, e as EventArgs)
Messagebox. Show ("you have clicked MyControl no "&_
MyControl. Index)
End Sub
Add or delete controls dynamically at runtime, as shown below:
'Visual Basic pseudocode
Dim I as Integer
For I = 1 to 5
'Insert code to create a control and assign a value to the property.
Next I
Visual Basic. NET allows you to copy some of these features. For example, you can use a proxy to bind events in multiple controls to a single event handler. However, it may be easier to integrate this function into a single dynamic and easy-to-manage component. In this article, we will create components that use the following content:
A set of indexes and sorting controls. The button set will be used for demonstration.
The event handler that processes the click event from the derived button.
Code that allows you to reference controls and their members through indexes.
Dynamically add and delete control code in the form.
Prerequisites
Familiar with components and their working principles.
I have some knowledge about polymorphism. For more information, see Polymorphism in Components ).

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.