如何动态生成textbox,并取得里面的值~
如何动态生成textbox,一行4个,
并取得里面的值~
------解决方案--------------------winfrom的话,
TextBox textBox1 = new TextBox();就可以生成textBox了,然后定义下位置就可以。
取值就直接textBox1.Text
------解决方案--------------------for(int i=0;i <table.Rows.Count;i++)
{
TextBox txb =(TextBox)table.Rows[i].Cells[0].Controls[0];
txb.Text就可以拉
------解决方案-------------------- private List <System.Windows.Forms.TextBox> textboxs;
private void CreateTextBox()
{
textboxs = new List <System.Windows.Forms.TextBox> ();
int y = 50;
int x = 10;
for (int i = 0; i < 4; i++)
{
System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
txt.Name = "textbox " + i.ToString();
txt.Size = new Size(20, 20);
txt.Location = new System.Drawing.Point(x, y);
this.Controls.Add(txt);
textboxs.Add(txt);
x += txt.Width + 10;
}
}
private void ReadTextBox()
{
foreach (System.Windows.Forms.TextBox txt in textboxs)
{
Console.WriteLine(txt.Text);
}
}