在Winfrom开发中,患者基本信息采集功能,保存数据后,有时需要清空界面的值需求,该函数可以根据自己需求去扩展使用
[code] /// <summary>/// 一键清空患者采集界面值/// </summary>/// <param name=\"sender\"></param>/// <param name=\"e\"></param>private void button1_Click(object sender, EventArgs e){//清空面板内控件的值ClearControlValue(this.panel1);}/// <summary>/// 清除容器里面某些控件的值/// </summary>/// <param name=\"parContainer\">容器名称</param>public void ClearControlValue(Control parContainer){for (int index = 0; index < parContainer.Controls.Count; index++){// 如果是容器内部控件,则递归调用自己if (parContainer.Controls[index].HasChildren){ClearControlValue(parContainer.Controls[index]);}else{switch (parContainer.Controls[index].GetType().Name){case \"TextBox\": //比较常用(parContainer.Controls[index] as TextBox).Text = \"\";break;case \"RadioButton\"://比较常用(parContainer.Controls[index] as RadioButton).Checked = false;break;case \"CheckBox\"://比较常用(parContainer.Controls[index] as CheckBox).Checked = false;break;case \"ComboBox\"://比较常用(parContainer.Controls[index] as ComboBox).Text = \"\";(parContainer.Controls[index] as ComboBox).SelectedIndex = -1;break;case \"DataGridView\":(parContainer.Controls[index] as DataGridView).DataSource = null;break;case \"ListBox\":(parContainer.Controls[index] as ListBox).Items.Clear();break;case \"DateTimePicker\":(parContainer.Controls[index] as DateTimePicker).Checked = false;break;}}}}