C# windowform controls clear

作者:互联网   出处:控件中国网   2014-11-05 19:21:56   阅读:1

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);

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat