差不多有2年没有写winform程序,一直都是写bs。最近项目需要,又开始着手写一个小功能的winform程序,需要动态获取xml文件的节点个数,生成跟节点个数一样的textbox,

最后还要获取操作人往动态生成的textbook输入的值。并把值写会到数据库中。上面是我winform程序的一部份功能。

以下总结以下生成与获取动态控件

     

 1 private string textBoxName = "newTextBox";
 2 
 3         private void button1_Click(object sender, EventArgs e)
 4         {
 5             TextBox ttt = new TextBox();
 6             ttt.Name = textBoxName;
 7             this.Controls.Add(ttt);
 8             ttt.Location = new Point(10, 10);
 9         }
10 
11         private void button2_Click(object sender, EventArgs e)
12         {
13             foreach (Control c in this.Controls)
14             {
15                 if (c.Name.Equals(textBoxName))
16                 {
17                     MessageBox.Show(c.Text);
18                     break;
19                 }
20             }
21         }
View Code

相关文章:

  • 2022-12-23
  • 2022-03-03
  • 2021-09-14
  • 2022-12-23
  • 2021-12-13
  • 2021-08-25
  • 2021-11-29
  • 2021-10-24
猜你喜欢
  • 2021-10-10
  • 2021-07-08
  • 2021-06-05
  • 2021-07-05
相关资源
相似解决方案