C# Why use SuspendLayout()?

C#Winforms

C# Problem Overview


I am reading up about SuspendLayout() and ResumeLayout(). What I can't figure out is, why should I do/use this. I know you use it when you add controls at runtime to a control-container.

It has something to do with setting properties like Dock, Anchor, Location, etc.

But I don't understand what the additional value is of Suspend- and ResumeLayout(). What does these methods take care for?

C# Solutions


Solution 1 - C#

Basically it's if you want to adjust multiple layout-related properties - or add multiple children - but avoid the layout system repeatedly reacting to your changes. You want it to only perform the layout at the very end, when everything's "ready".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartijnView Question on Stackoverflow
Solution 1 - C#Jon SkeetView Answer on Stackoverflow