This documentation is archived and is not being maintained.

Control.SuspendLayout Method

Temporarily suspends the layout logic for the control.

[Visual Basic]
Public Sub SuspendLayout()
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 allow the changes to take effect.


[Visual Basic, C#, C++] The following example adds two buttons to a form. The example transactions the addition of the buttons by using the SuspendLayout and ResumeLayout methods.

[Visual Basic] 
Private Sub AddButtons()
   ' Suspend the form layout and add two buttons.
   Dim buttonOK As New Button()
   buttonOK.Location = New Point(10, 10)
   buttonOK.Size = New Size(75, 25)
   buttonOK.Text = "OK"
   Dim buttonCancel As New Button()
   buttonCancel.Location = New Point(90, 10)
   buttonCancel.Size = New Size(75, 25)
   buttonCancel.Text = "Cancel"
   Me.Controls.AddRange(New Control() {buttonOK, buttonCancel})
End Sub

private void AddButtons()
   // Suspend the form layout and add two buttons.
   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});

    void AddButtons() {
        // Suspend the form layout and add two buttons.
        Button* buttonOK = new Button();
        buttonOK->Location =  Point(10, 10);
        buttonOK->Size =  System::Drawing::Size(75, 25);
        buttonOK->Text = S"OK";

        Button* buttonCancel = new Button();
        buttonCancel->Location =  Point(90, 10);
        buttonCancel->Size =  System::Drawing::Size(75, 25);
        buttonCancel->Text = S"Cancel";
        Control* temp5 [] = {buttonOK, buttonCancel};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | ResumeLayout | Layout