asp.net| Dynamic | Control from the beginning of contact with the development of the vast majority of 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);
}
}
}
}