Clearing the Textboxes in Windows Application

This is the article for clearing the textboxes in windows application. This will help to reduce the lines of bunch of code explicitly clear the textbox like

  1.  textbox1.text="";  
  2.     :  
  3.     :  
  4.  textbox10.text="";  
  5.   
  6. if we clear the all textbox in the form it will perfect.  
  7.   
  8.  public void ClearTextBoxes(Control control)  
  9.         {  
  10.             foreach (Control c in control.Controls)  
  11.             {  
  12.             if (c is TextBox)  
  13.             {  
  14.             ((TextBox)c).Clear();  
  15.             }  
  16.             if (c.HasChildren)  
  17.             {  
  18.             ClearTextBoxes(c);  
  19.             }  
  20.             }  
  21.         } 

* create the object for the Control class, This holds the reference of all the controls in the form.

* check the control is Textbox

  1. if (c is TextBox)  
  2. {  
  3. ((TextBox)c).Clear();  

* Some times we need situation null the textbox values in nested controls like Tabcontrol etc, That situation we need to check the other textboxes in the nested control(Tabcontrol).

  1. if (c.HasChildren)  
  2. {  
  3. ClearTextBoxes(c);  

It will find the children of the form and check that have a textbox. Its a recursive function. Next time this function pass the reference of the child control.