title: Setting the control's parent in form designer
body: <p>This <a href="https://msdn.microsoft.com/en-us/library/aa446542.aspx" rel="nofollow noreferrer">MSDN article</a> offers some good advice about manually customising the form designer to improve performance:</p>
  
  <ul>
  <li><p>Reduce the number of method and property calls on controls during startup. For example, Controls.Bounds is a better option than calls to Control.Location and Control.Size.</p></li>
  <li><p>Create the form from the top down. In nested control hierarchies, set the parent property of containers (using the above rule) before adding controls to the container. As in the BigForm application, the panels had their parent property set to the form before the 40 controls were connected to the panel. If further containers exist lower in the hierarchy, the same changes should be applied.</p></li>
  </ul>
  
  <p>I have followed the 1st bit of advice, replacing:</p>
  
  <pre><code>this.MyControl.Location = new System.Drawing.Point(5, 5);
  this.MyControl.Size = new System.Drawing.Size(630, 90);
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>this.MyControl.Bounds = new System.Drawing.Rectangle(5, 5, 630, 90);
  </code></pre>
  
  <p>This resulted in a super 20% (about 200ms) speed-up on one form. I'm trying to follow the 2nd bit of advice and not quite sure how to proceed. The <code>Designer.cs</code> file contains code like this:</p>
  
  <pre><code>this.Controls.Add(this.pnlHeader);
  </code></pre>
  
  <p>but not the code I was expecting (according to the example):</p>
  
  <pre><code>this.pnHeader.Parent = this;    // Not in the Designer
  </code></pre>
  
  <p>The code <code>this.Controls.Add(this.pnlHeader);</code> appears at the bottom of <code>InitializeComponent</code>. Is the advice suggesting moving the code to the top or something else entirely?</p>