title: Create a function to clear a windows form(C#)
body: <p>I'm trying to clear a windows form using a C# function.</p>
  
  <p>I know the method for clearing individual controls like</p>
  
  <pre><code>username.Clear();
  password.Clear();
  </code></pre>
  
  <p>But, it is a large form an the clear function looks a bit awkward.</p>
  
  <p>I found a code online which looks like this.</p>
  
  <pre><code>private void ClearFields(System.Windows.Forms.Control.ControlCollection collection)
  {
      foreach (Control c in collection)
      {
          if (c.HasChildren)
              ClearFields(c.Controls);
          if (c is TextBox)
          {
              if (!string.IsNullOrEmpty(c.Text))
                  c.Text = "";
          }
      }
  }
  </code></pre>
  
  <p>But, for this code, the password field alone does not get cleared. I'm clearing "TextBox" controls alone. Do I have to specify any other control name for clearing a password field even though both are basically "TextBox" controls?</p>