c# 遍历当前应用程序 的所有控件

来源:百度知道 编辑:UC知道 时间:2024/06/01 23:30:03
c# 遍历当前应用程序 的所有控件

怎么实现
我要遍历所有控件,然后可以对这些控件实现失效控制。

下面这段程序也许对你有帮助,因为不知道你的具体需求,我这个例子是用来遍历所有的textBox控件,然后将其全部清空的
private void ClearTextBox()
{
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is TextBox)
{
TextBox tb = new TextBox();
tb = (TextBox)control;
tb.Text =string.Empty;
}

}
}

foreach(Control con in this.Controls)
{

}

你要干么?