C# Why use SuspendLayout()

cwinforms

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?

Best Answer

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".