Dynamically generate control arrays in. net

Source: Internet
Author: User
The majority of developers started from basic, and Windows developers started from VB. The changes from VB to VB.net are indeed not small, in the past, a lot of control arrays were used in. net, but the time is okay. This is one of my Program I used it. Today I pasted this class, which I saw from msdn a long time ago, according to what he said.

//*********************************

// Dynamically add and delete array controls

// Students who design the project can reference this class.

// Fan weixiao

//*********************************

Namespace gradesystem

{

//**************************

// Class textboxarray implements dynamic addition and Deletion

// Textbox Functions

//**************************

Public class textboxarray: system. Collections. collectionbase

{

Private readonly system. Windows. Forms. Form hostform;

//Constructor

Public textboxarray (system. Windows. Forms. form host)

{

Hostform = host;

}

// Add a Textbox Control Using the addnewtextbox Method

Public void addnewtextbox ()

{

If (this. Count <7)

{

// Create a new textbox instance.

System. Windows. Forms. textbox atextbox = new system. Windows. Forms. Textbox ();

// Add it to the internal list of the Set

This. List. Add (atextbox );

// Add textbox to the set list of the forms referenced by the hostform Field

Hostform. Controls. Add (atextbox );

// Set the initial attribute

Atextbox. Left = (count-1) * 130 + 70;

Atextbox. Top = 160;

Atextbox. width = 120;

Atextbox. borderstyle = system. Windows. Forms. borderstyle. fixedsingle;

Atextbox. font = new system. Drawing. Font ("verdana", 40, system. Drawing. fontstyle. Bold );

Atextbox. Tag = This. count;

// Initial Value

Atextbox. Text = "9.9 ";

Atextbox. forecolor = system. Drawing. color. Red;

}

}

// Create an index

Public System. Windows. Forms. textbox this [int Index]

{

Get

{

Return (system. Windows. Forms. textbox) This. list [Index];

}

}

// The remove method is used to delete controls.

Public void remove ()

{

If (this. Count> 0)

{

Hostform. Controls. Remove (this [This. Count-1]);

This. List. removeat (this. Count-1 );

}

}

}

}

Sorry, I used editplus to open the CS file, and then pasted it with Garbled text. this class may be used by my students during the design of the project. Some people will try it, so I can paste it here to copy it directly from here.

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.