在c#中很多时候都会动态生成一些控件,但又想对这些控件进行一些其他的操作。该如何获取这些控件了,其实方法很简单。
以textBox为例:
foreach(System.Windows.Forms.Control control in this.Controls) { if (control is System.Windows.Forms.TextBox) { System.Windows.Forms.TextBox tb =(System.Windows.Forms.TextBox)control ; tb.Text = "控件"; } }