title: How to get a list of all controls on WinForm even those in SplitContainers or Panels
body: <p>A have several containers on my WinForm like Panel, SpliContainer, StatusStrip... Each of these containers contains basic elements like buttons or textboxs. I need to iterate thru all form controls (even those in Panels, SplitContainers, StatusStrip) to find some control. I try with recursive function </p>
  
  <pre><code>    ListAllControls(Control MainControl)
      {
          foreach (Control control in MainControl.Controls)
          {
              if (control.HasChildren)
              {
                  ListAllControls(control);
              }
              else
              { 
                  // do something with this control
              }
          }
      }
  </code></pre>
  
  <p>but I dont get controls that are in containers!?</p>
  
  <p>UPDATE:</p>
  
  <p>I have a Form with SplitContainer, Panel and StatuStrip. In each of these controls I have several child controls like toolStripStatusLabel1 in StatuStrip1. Problem is when I try to find for example control toolStripStatusLabel1 in StatuStrip via function ListAllControls I can't find it!? I don't know any another approach to get all controls from form. Complete code is here:</p>
  
  <pre><code>class Control_Finder
  {
  
      private Control founded_control = null;
  
      public Control Founded_Control
      {
          get { return founded_control; }
      }
  
      public void ListAllControls(Control MainControl, string SearchForControl)
      {
          foreach (Control control in MainControl.Controls)
          {
              if (control.HasChildren)
              {
                  ListAllControls(control, SearchForControl);
              }
              else
              {
                  // check if control has searched name
                  if (control.Name == SearchForControl)
                  {
                      founded_control = control;
                      return;
                  }
              }
          }
      }
  } // class
  </code></pre>
  
  <p>Sample:</p>
  
  <pre><code>Form Me = this;
  Control_Finder Test = new Control_Finder();
  Test.ListAllControls(Me, "toolStripStatusLabel1");
  
  if (Test.Founded_Control != null)
  {
        MessageBox.Show("I found control " + Test.Founded_Control.Name + "!");
  }
  else
  {
        MessageBox.Show("Didn't found! :(");
  }
  </code></pre>
  
  <p>For this sample i get <em>Didn't found :(</em> but if I use StatusStrip1 I get <em>"I found control StatusStrip1!"</em>
  I hope that the question now more clearly than before.</p>