//遍歷窗體所有控件,
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

