title: Detecting Controls in VB.NET Forms
body: <p>I wrote the code below to delete control in another VB.NET Form; that workd fine; But the code cannot Detect that the Form has NO Controls; What is wrong with the code please:</p>
  
  <pre><code>Sub DeleteControls() ' WORKING
      For i As Integer = Form2.Controls.Count - 1 To 0 Step -1
          Dim ctrl = Form2.Controls(i)
          ctrl.Dispose()
      Next
  End Sub
  
  Sub TestForm() ' NOT WORKING
      If Form2.Controls Is Nothing Then
          MessageBox.Show("Form2 has No Controls")
      End If
  End Sub
  </code></pre>
  
  <p>Thanks</p>