views:

208

answers:

2

I can't quite think of how to phrase the question to be precise, but hopefully my meaning will be clear. Do Control.SuspendLayout and Control.ResumeLayout keep count?

To put it another way, If I call SuspendLayout twice, and ResumeLayout once, is layout still suspended?

A: 

If I call SuspendLayout twice, and ResumeLayout once, is layout still suspended?

No. Layout is resumed.

Joel Coehoorn
+2  A: 

There's little reason left to get stuck on a question like this. The source code is available, titled "Reference Source". The best way to get it is with the .NET Mass Downloader. Not every .NET assembly has its source code published, your backup is the venerable Reflector.

Anyhoo, the source code looks roughly like this:

private byte layoutSuspendCount;

public void SuspendLayout() {
  layoutSuspendCount++;
  if (layoutSuspendCount == 1) OnLayoutSuspended();
}

public void ResumeLayout() {
  ResumeLayout(true);
}

public void ResumeLayout(bool performLayout) {
  if (layoutSuspendCount > 0) {
    if (layoutSuspendCount == 1) OnLayoutResuming(performLayout);
    layoutSuspendCount--;
    if (layoutSuspendCount == 0 && performLayout) {
      PerformLayout();
    }
  }
} 

internal void PerformLayout(LayoutEventArgs args) {
  if (layoutSuspendCount > 0) {
    //...
    return;
  }
  //etc...
}

So the answer to your question is: Yes.

Hans Passant