Live Chat Icon For mobile
Live Chat Icon

How do SuspendLayout and ResumeLayout work ?

Platform: WPF| Category: Layouts

SuspendLayout and ResumeLayout only prevent ’OnLayout’ from being called. Additionally they only prevent OnLayout from being called for that particular control. So if you have a Form with a Panel in it and call SuspendLayout on the Form, the Panel’s layout will not be suspended.

[C#]

   private void button1_Click(object sender, EventArgs e) 
{
   this.Layout += new LayoutEventHandler(Form1_Layout);
   panel1.Layout += new LayoutEventHandler(Panel1_Layout);

   // Test one - calling PerformLayout here does not call Form1_Layout.
   this.SuspendLayout();
   this.PerformLayout();
   this.ResumeLayout(false);

   // Test two - calling PerformLayout here calls Panel1_Layout.
   // Child controls are not suspended when the parent is suspended.
   this.SuspendLayout();
   panel1.PerformLayout();
   this.ResumeLayout(false);

   // Test three, properly suspending layout.
   this.SuspendLayout();
   panel1.SuspendLayout();
   panel1.PerformLayout();   // <--- Layout event on Panel NOT called
   panel1.ResumeLayout(false); 
   this.ResumeLayout(false);

   panel1.Layout -= new LayoutEventHandler(Panel1_Layout);
   this.Layout -= new LayoutEventHandler(Form1_Layout);
 }

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.