Yes you can create an array of textboxes.Look at the code below.
public partial class Form1 : Form
{
TextBox[] txt = new TextBox[3]; //Creating an array of textbox //references NOT an array of textboxes.
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for(int i = 0; i < txt.Length; i++)
{
txt[i] = new TextBox(); //Each textbox reference must show a //textbox...
this.Controls.Add(txt[i]); //Add the current textbox to the //form.
}
}
Now why we wrote txt[i] = new TextBox(); ???
Because when you initialize the array of textbox references , each reference shows "null".So when you write txt[i].Text = "something" without write txt[i] = new TextBox(); it will cause an error(Null reference exception).
public partial class Form1 : Form
{
TextBox[] txt = new TextBox[3];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
txt[0].Text = "something"; //These assignments will cause Null //Reference Exception because each of reference shows "null";
txt[1].Text = "something else";
.......
}
}
Note that all of the textboxes have the same location on the form when they were added to the form.You must change their location with the code below :
txt[0].Location = new Point(45,89);
txt[1].Location = new Point(34,88);
......
But this will cause a little mess for 30 textboxes...:P
If the textbox positions are proportional you may solve this by using a loop...