WinForms: No Pending Calls to SuspendLayout()

Viewed 84
1 Answers

What they are saying is, you must call ResumeLayout one-for-one with SuspendLayout.

So, to guard against this state, you could do this:

MyControl.SuspendLayout();
try
{
    // do some work
}
finally
{
    MyControl.ResumeLayout();
}

That way if the "do some work" block throws an exception, you can be assured that ResumeLayout is always called, otherwise the suspend/resume will become unbalanced and your UI will not update properly.

In other words, if you do this:

MyControl.SuspendLayout();
MyControl.SuspendLayout();
MyControl.ResumeLayout();

then ResumeLayout will not have the desired affect.

But, this will:

MyControl.SuspendLayout();
MyControl.SuspendLayout();
MyControl.ResumeLayout();
MyControl.ResumeLayout();
Related