title: Dynamically swapping out or toggling visibility of controls
body: <p>I have a <code>TreeView</code> in a form, that is dock-filled to a groupbox. The problem to solve is, that there is an operation that is run on a <code>Task</code>, which loads data from a server application. When this is running, there should be a progress indicator displayed in the location of the <code>TreeView</code>. That is, it should be shown instead of the <code>TreeView</code>, and take its place fully. The following is what the code for this looks like:</p>
  
  <pre><code>private async void preload_data(object sender, System.EventArgs args)
  {
      try
      {
          // the treeView should be disabled/invisible at this point
          // make the CircularProgressBar enabled/visible
  
          // get the information from the server
          await Configuration.network.fetch_stuff();
      }
      catch (Exception ex)
      {
          // something bad happened
      }
      finally
      {
          // whatever happened, the treeView should be back 
      }
  }
  </code></pre>
  
  <p>The <code>CircularProgressBar</code> (a third-party control) should appear as in the code above, and should replace the <code>TreeView</code>. It should fill the exact same space as the <code>TreeView</code> would, which is dock-filled. Below is a screenshot of this:
  <a href="https://i.stack.imgur.com/CvYhn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CvYhn.png" alt="enter image description here"></a></p>
  
  <p>This form and all its controls have been designed in the designer, and I don't want to do it there, I want to do it programmatically. What is the best way to go about this? I have looked at examples of <code>Controls.Remove()</code> and <code>Controls.Add()</code>, but it's not clear if that fits this purpose.</p>