Dynamic generation of control arrays in. Net

Source: Internet
Author: User
Tags arrays count
Dynamic | control | Arrays start from basic contact development accounted for the vast majority, and the use of VB started to contact win development is also accounted for the vast majority of From VB to vb.net change is really not small, many of the previously used control arrays are not in. NET, but the time is OK, this is a program I used, today put this class, this is a long time to see from MSDN, according to what he said to do.

//*********************************
Add dynamic, delete array control
Students who do project design can cite this class
Fan Wei Shaw
//*********************************
Namespace Gradesystem
{
//**************************
Class Textboxarray enables dynamic additions and deletions
Functions of the TextBox
//**************************
public class TextBoxArray:System.Collections.CollectionBase
{
Private ReadOnly System.Windows.Forms.Form Hostform;
Constructors
Public Textboxarray (System.Windows.Forms.Form Host)
{
Hostform=host;
}
Addnewtextbox method to add a TextBox control
public void Addnewtextbox ()
{
if (this. COUNT<7)
{
Build a new TextBox instance.
System.Windows.Forms.TextBox atextbox=new System.Windows.Forms.TextBox ();
Add it to the internal list of collections
This. List.add (Atextbox);
Add a TextBox to the list of collections in the form referenced by the Hostform field
HOSTFORM.CONTROLS.ADD (Atextbox);
Set initial properties
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", 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];
}
}
Remove method to delete a control
public void Remove ()
{
if (this. COUNT>0)
{
HostForm.Controls.Remove (this[this. Count-1]);
This. List.removeat (this. COUNT-1);
}
}
}
}



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.