Export (0) Print
Expand All
Expand Minimize

Control.SuspendLayout Method

Temporarily suspends the layout logic for the control.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public void SuspendLayout ()
public void SuspendLayout ()
public function SuspendLayout ()

The layout logic of the control is suspended until the ResumeLayout method is called.

The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. For example, you would typically call the SuspendLayout method, then set the Size, Location, Anchor, or Dock properties of the control, and then call the ResumeLayout method to enable the changes to take effect.

The SuspendLayout calls must be equal to zero before ResumeLayout can be successfully called.

NoteNote

When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. After adding the controls to the parent control, call the ResumeLayout method. This will increase the performance of applications with many controls.

The following code example adds two buttons to a form. The example transactions the addition of the buttons by using the SuspendLayout and ResumeLayout methods.

private void AddButtons()
{
   // Suspend the form layout and add two buttons.
   this.SuspendLayout();
   Button buttonOK = new Button();
   buttonOK.Location = new Point(10, 10);
   buttonOK.Size = new Size(75, 25);
   buttonOK.Text = "OK";

   Button buttonCancel = new Button();
   buttonCancel.Location = new Point(90, 10);
   buttonCancel.Size = new Size(75, 25);
   buttonCancel.Text = "Cancel";
      
   this.Controls.AddRange(new Control[]{buttonOK, buttonCancel});
   this.ResumeLayout();
}

private void AddButtons()
{
    // Suspend the form layout and add two buttons.
    this.SuspendLayout();
    Button buttonOK = new Button();
    buttonOK.set_Location(new Point(10, 10));
    buttonOK.set_Size(new Size(75, 25));
    buttonOK.set_Text("OK");

    Button buttonCancel = new Button();
    buttonCancel.set_Location(new Point(90, 10));
    buttonCancel.set_Size(new Size(75, 25));
    buttonCancel.set_Text("Cancel");

    this.get_Controls().AddRange(new Control[] {buttonOK, buttonCancel});
    this.ResumeLayout();
} //AddButtons

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft