title: Before Disposing either form or usercontrol
body: <p>I have code which i use to do some Dispose for my forms and user controls (below):</p>
  
  <pre><code>Public Shared Sub DisposeUserControlControls(parent As Control)
          For ix As Integer = parent.Controls.Count - 1 To 0 Step -1
              Dim ctl = parent.Controls(ix)
              If (TypeOf ctl Is UserControl) Or (TypeOf ctl Is Form) Then
                  ctl.Dispose()
              End If
          Next
      End Sub
  </code></pre>
  
  <p>However for some of my either forms or user controls i would like to execute some code before they process with Dispose. Is there any way when either form or user control get signal to be disposed to execute some code before dispose? I heard something about implement IDisposable.</p>
  
  <p><strong>Additional question:</strong></p>
  
  <p>As far as you said to only call this inside dispose:</p>
  
  <pre><code> MyBase.Dispose(disposing)
  </code></pre>
  
  <p>I noticed that in class designer class it is as following below with additional check if disposing... beisdes your line. Question would be should i also include it or MyBase.Dispose(disposing) is jsut enough? There is also attribute included at the top.</p>
  
  <pre><code>'Form overrides dispose to clean up the component list.
          &lt;System.Diagnostics.DebuggerNonUserCode()&gt;
          Protected Overrides Sub Dispose(ByVal disposing As Boolean)
              Try
                  If disposing AndAlso components IsNot Nothing Then
                      components.Dispose()
                  End If
              Finally
                  MyBase.Dispose(disposing)
              End Try
          End Sub
  </code></pre>