C# winform 动态生成的Textbox,假如生成了BTextbox1---BTextbox xx 然后把生成的xx个框的数值保存下来,留着下次开软件读取
private void button1_Click(object sender, EventArgs e)
{
int row = 0;//row 行
int shuju = int.Parse(textBox1.Text);
for (int i = 0; i < shuju; i++)
{
if (i % 1 == 0 && i != 0)
{
row++;
}
TextBox box = new TextBox();
TextBox box1 = new TextBox();
box.Name = "ATextBox" + i.ToString();
box1.Name = "BTextBox" + i.ToString();
box.Multiline = true;
box1.Multiline = true;
box.Text = string.Format("读取数据{0}", i + 1);
box1.Text = string.Format("寄存器名称{0}", i + 1);
box.Size = new Size(150, 25);//格子大小
box1.Size = new Size(150, 25);
box.Location = new Point(600 + i % 1 * 180, 30 + row * 40);
box1.Location = new Point(400 + i % 1 * 180, 30 + row * 40);
this.Controls.Add(box);
this.Controls.Add(box1);
}
}
private void button2_Click(object sender, EventArgs e)
{
iniFile.WriteValue("ABC", "个数", textBox1.Text);
}
foreach (Control c in Controls)
{
if (c in TextBox)
{
TextBox t = c as TextBox;
t.Name是名字,t.Text是值,你存入文件即可
}
}
<input class="easyui-textbox" name="phone" style="width:100%" data-options="label:'电话:',required:true,validType:'phoneRex'">
List<string> textboxValues = new List<string>();
for (int i = 0; i < shuju; i++)
{
textboxValues.Add(box3.Text);
}
foreach (var item in textboxValues)
{
iniFile.WriteValue("SectionName", box3.Name, item.ToString());
}
}
已经解决了用这个代码 存在本地的配置文件里