title: Can layout-adjusting statements be re-arranged in code generated by Designer?
body: <p>In order to easily merge changes in <code>*.Designer.vb</code> files (the same applies to <code>*.Designer.cs</code> files), I need to <strong>sort content of certain code sections</strong> in files generated by Designer because <a href="https://stackoverflow.com/questions/486670/why-does-c-sharp-designer-generated-code-like-form1-designer-cs-play-havoc-wit">Visual Studio is sometimes reordering them randomly</a>. I can see 16 merge conflicts before rearranging, <em>zero</em> conflicts after.</p>
  
  <p>I have no doubt on sorting declarations etc. But my doubt is about <code>ResumeLayout(false)</code> and <code>PerformLayout()</code> calls at end of <code>InitializeComponent()</code> method. Despite some learning, I don't <em>fully</em> understand yet how they work (<a href="https://social.msdn.microsoft.com/Forums/windows/en-US/0732a620-a0e3-4ba3-b742-d6e0b6f97442/how-do-i-get-the-designer-to-autogenerate-performlayout-for-my-custom-control?forum=winformsdesigner" rel="nofollow noreferrer">practical details found here</a>) and therefore I'm seeking an answer whether it is safe to re-arrange the order of objects they are called upon. Testing with Designer did not show problems so far but I'm asking to be sure.</p>
  
  
  
  <h3>Original order in Form1.Designer.vb</h3>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub InitializeComponent()
  
      '...initializations of controls are left out
  
      '
      'Form1
      '
      Me.ClientSize = New System.Drawing.Size(784, 562)
      Me.Controls.Add(Me.TableLayoutPanel1)
      Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
      Me.Name = "Form1"
      Me.Text = "Form1 Title"
  
      'original order created by Designer
      CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
      Me.TableLayoutPanel1.ResumeLayout(False)
      Me.TableLayoutPanel1.PerformLayout()
      Me.page2.ResumeLayout(False)
      Me.page2.PerformLayout()
      Me.page1.ResumeLayout(False)
      Me.TableLayoutPanel2.ResumeLayout(False)
      Me.TableLayoutPanel2.PerformLayout()
      Me.TabCtl1.ResumeLayout(False)
      CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
      'end of section in question
  
      Me.ResumeLayout(False)
  
  End Sub
  </code></pre>
  
  <h3>Modified order in Form1.Designer.vb</h3>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub InitializeComponent()
  
      '...initializations of controls are left out
  
      '
      'Form1
      '
      Me.ClientSize = New System.Drawing.Size(784, 562)
      Me.Controls.Add(Me.TableLayoutPanel1)
      Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
      Me.Name = "Form1"
      Me.Text = "Form1 Title"
  
      'the following lines (or pairs) were arranged alphabetically - is it OK?
      CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
      CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
      Me.page1.ResumeLayout(False)
      Me.page2.ResumeLayout(False)
      Me.page2.PerformLayout()
      Me.TabCtl1.ResumeLayout(False)
      Me.TableLayoutPanel1.ResumeLayout(False)
      Me.TableLayoutPanel1.PerformLayout()
      Me.TableLayoutPanel2.ResumeLayout(False)
      Me.TableLayoutPanel2.PerformLayout()
      'end of sorted groups
  
      Me.ResumeLayout(False)
  
  End Sub
  </code></pre>
  
  <p>Is such a change always safe? Or should the commands be arranged with respect to tree hierarchy of controls (parent listed first) instead of alphabetical ordering?</p>
  
  <p>EDIT: some further research shows me, that form designer puts ancestors first, but enforces no other particular ordering. Order of controls is determined only by order of <code>Control.Add()</code> calls. Maybe I can improve sorting method to reflect this and I should be safe.</p>