C# windowform controls clear
01 /// <summary>
02 /// 遍曆清除指定的控件
03 /// 塗聚文 2011-10-18
04 /// 締友計算機信息技術有限公司
05 /// </summary>
06 /// <param name="con"></param>
07 public void ClearControl(Control.ControlCollection con)
08 {
09 foreach (Control C in con)
10 {
11 if (C.GetType().Name == "TextBox")
12 if (((TextBox)C).Visible == true)
13 ((TextBox)C).Clear();
14 if (C.GetType().Name == "MaskedTextBox")
15 if (((MaskedTextBox)C).Visible == true)
16 ((MaskedTextBox)C).Clear();
17 if (C.GetType().Name == "ComboBox")
18 if (((ComboBox)C).Visible == true)
19 ((ComboBox)C).Text = "";
20 if (C.GetType().Name == "PictureBox")
21 if (((PictureBox)C).Visible == true)
22 ((PictureBox)C).Image = null;
23 }
24 }
25
26 //在winForm調用方法
27 Control.ControlCollection coll = this.Controls;
28 formOperatin.ClearControl(coll);