C#遍历窗体所有控件或某类型所有控件

//遍历窗体所有控件,
foreach (Control control in this.Controls)
{
//遍历后的操作... control.Enabled = false; }

 遍历某个panel的所有控件

foreach (Control control in this.panel4.Controls)
{
    control.Enabled = false;
}

 

遍历所有TextBox类型控件或者所有DateTimePicker控件

复制代码
foreach (Control control in this.Controls)
{
  //遍历所有TextBox... if (control is TextBox) { TextBox t = (TextBox)control; t.Enabled = false; }
  //遍历所有DateTimePicker... if (control is DateTimePicker) { DateTimePicker d = (DateTimePicker)control; d.Enabled = false; } }
复制代码

 

转载:

https://www.cnblogs.com/Donnnnnn/p/6088489.html

 

转载于:https://www.cnblogs.com/sunice/p/10062950.html

你可能感兴趣的:(C#遍历窗体所有控件或某类型所有控件)