Search code examples
c#winformswindows-forms-designergenerated-code

C#: Does ResumeLayout(true) do the same as ResumeLayout(false) + PerformLayout()?


I have looked at the generated designer code of Forms and UserControls, and in the InitializeComponent() method they always start with

    this.SuspendLayout();

and end with

    this.ResumeLayout(false);
    this.PerformLayout();

But from what I can see in the msdn documentation of those methods, wouldn't ending with

    this.ResumeLayout(true); // Or just this.ResumeLayout()

do the exact same thing? Or am I missing something here?

Asking because I will be adding a bunch of controls in a different method, and thought I should do the suspend-resume routine to be nice and efficient. But can't figure out what the reason for those two method calls are when you can seemingly just use one...


Solution

  • Using reflector:

    this.ResumeLayout() is equal to this.ResumeLayout(true)
    

    But

    this.ResumeLayout(true) is not equal to this.ResumeLayout(false) + this.PerformLayout()
    

    Reason:
    When ResumeLayout is called with false, there is a control collection that is looped through and the LayoutEngine calls InitLayout on each of the controls in the layout.