int m=int.Parse(textBox1.Text); int n=int.Parse(textBox2.Text); TextBox[] tbs=new TextBox[m*n]; for(int i=0;i<tbs.Length;i++) { tbs[i]=new TextBox(); this.Controls.Add(tbs[i]); } 自己处理下添加的位置,我这里没考虑,有可能都重叠在一起了。
public void btnAdd(object sender,EventArgs e) { int m = int.Parse(this.textBox1.Text.Trim()); int n = int.Parse(this.textBox2.Text.Trim()); for(int i =0;i<m*n;i++) { TextBox tb = new TextBox(); tb.ID = "tb"+(i+3); //从textBox3开始 tb.Width = 100; tb.Height= 20; this.Controls.Add(tb); } }
private void button1_Click(object sender, EventArgs e) { int result = 0; int m = 0; int n = 0; if (!string.IsNullOrEmpty(textBox1.Text) && Int32.TryParse(textBox1.Text, out result)) { m = int.Parse(textBox1.Text); } if (!string.IsNullOrEmpty(textBox2.Text) && Int32.TryParse(textBox2.Text,out result)) { n = int.Parse(textBox2.Text); } result = m * n; if (result == 0) { return; } for (int i = 0; i < result; i++) { TextBox txt = new TextBox(); txt.Name = "txt" + i.ToString(); txt.Top = i * 20; this.Controls.Add(txt); } }
int n=int.Parse(textBox2.Text);
TextBox[] tbs=new TextBox[m*n];
for(int i=0;i<tbs.Length;i++)
{
tbs[i]=new TextBox();
this.Controls.Add(tbs[i]);
}
自己处理下添加的位置,我这里没考虑,有可能都重叠在一起了。
public void btnAdd(object sender,EventArgs e)
{
int m = int.Parse(this.textBox1.Text.Trim());
int n = int.Parse(this.textBox2.Text.Trim());
for(int i =0;i<m*n;i++)
{
TextBox tb = new TextBox();
tb.ID = "tb"+(i+3); //从textBox3开始
tb.Width = 100;
tb.Height= 20;
this.Controls.Add(tb);
}
}
private void button1_Click(object sender, EventArgs e)
{
int result = 0;
int m = 0;
int n = 0;
if (!string.IsNullOrEmpty(textBox1.Text) &&
Int32.TryParse(textBox1.Text, out result))
{
m = int.Parse(textBox1.Text);
} if (!string.IsNullOrEmpty(textBox2.Text) &&
Int32.TryParse(textBox2.Text,out result))
{
n = int.Parse(textBox2.Text);
} result = m * n; if (result == 0)
{
return;
} for (int i = 0; i < result; i++)
{
TextBox txt = new TextBox();
txt.Name = "txt" + i.ToString();
txt.Top = i * 20;
this.Controls.Add(txt);
}
}