Export (0) Print
Expand All
Expand Minimize

Control.SuspendLayout Method

Temporarily suspends the layout logic for the control.

[Visual Basic]
Public Sub SuspendLayout()
[C#]
public void SuspendLayout();
[C++]
public: void SuspendLayout();
[JScript]
public function SuspendLayout();

Remarks

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.

Example

[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.
   Me.SuspendLayout()
   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})
   Me.ResumeLayout()
End Sub

[C#] 
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();
}

[C++] 
private:
    void AddButtons() {
        // Suspend the form layout and add two buttons.
        this->SuspendLayout();
        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};
        this->Controls->AddRange(temp5);
        this->ResumeLayout();
    }

[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.

Requirements

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

Show:
© 2014 Microsoft