C#如何获得动态生成的控件

在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 = "控件";

    }

  }


获取到相应的控件之后,就可以对该控件的属性进行操作了。

猜你喜欢

转载自blog.csdn.net/zhushiq1234/article/details/52013044