title: VB.NET Iterating through control containers
body: <p>How do I go about looping through all the controls within a container, and all the controls in the container of a containing control, and so on.</p>
  
  <pre><code>Form
  -Panel
  --Control
  --Tab
  ----Control
  ----Control
  --Tab
  ----Control
  </code></pre>
  
  <p>The following only retrieves -Panel and none of the other controls</p>
  
  <pre><code>For Each cntrl As Control In Me.Controls
  
  Next
  </code></pre>
  
  <p>How can I retrieve them all in a For Each loop without an If/Then for every level in the stack?</p>
  
  <p>EDIT: </p>
  
  <pre><code>Dim ctl As Control = Me
  Do
      ctl = Me.GetNextControl(ctl, True)
      'Do whatever you have to ctl
  Loop Until ctl Is Nothing
  </code></pre>
  
  <p>This is so far the best method I found of doing this. </p>