private void btnClear_Click(object sender, EventArgs e)
{
ClearCntrValue(this.pnlContent);
}
[csharp] view plaincopyprint?
/// <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 = "";
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;
}
}
}
}

  以上介绍的是C# WinForm清空界面控件值的小技巧,希望对你有所帮助