/// <summary>
/// 清除容器里面某些控件的值
/// </summary>
/// <param name="parContainer">容器类控件</param>
public void ClearCntrValue(Control parContainer)
{
for (int index = 0; index < parContainer.Controls.Count; index++)
{
// 如果是容器类控件,递归调用自己
if (parContainer.Controls[index].HasChildren)
{
ClearCntrValue(parContainer.Controls[index]);
}
else
{
switch(parContainer.Controls[index].GetType().Name)
{
case "TextBox":
parContainer.Controls[index].Text = string.Entity;
break;
case "RadioButton":
((RadioButton)(parContainer.Controls[index])).Checked = false;
break;
case "CheckBox":
((CheckBox)(parContainer.Controls[index])).Checked = false;
break;
case "ComboBox":
((ComboBox)(parContainer.Controls[index])).Text = "";
break;
}
}
}
}
用法:
private void btnClear_Click(object sender, EventArgs e)
{
ClearCntrValue(this.pnlContent);
}