Control.SuspendLayout Control.SuspendLayout Control.SuspendLayout Control.SuspendLayout Method

定义

临时挂起控件的布局逻辑。Temporarily suspends the layout logic for the control.

public:
 void SuspendLayout();
public void SuspendLayout ();
member this.SuspendLayout : unit -> unit
Public Sub SuspendLayout ()

示例

下面的代码示例将两个按钮添加到窗体。The following code example adds two buttons to a form. 示例事务使用的按钮添加SuspendLayoutResumeLayout方法。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 = gcnew Button;
      buttonOK->Location = Point(10,10);
      buttonOK->Size = System::Drawing::Size( 75, 25 );
      buttonOK->Text = "OK";
      Button^ buttonCancel = gcnew Button;
      buttonCancel->Location = Point(90,10);
      buttonCancel->Size = System::Drawing::Size( 75, 25 );
      buttonCancel->Text = "Cancel";
      array<Control^>^temp5 = {buttonOK,buttonCancel};
      this->Controls->AddRange( temp5 );
      this->ResumeLayout();
   }
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 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

注解

控件的布局逻辑被挂起,直到ResumeLayout调用方法。The layout logic of the control is suspended until the ResumeLayout method is called.

SuspendLayoutResumeLayout方法将相继配合使用来禁止显示多个Layout事件时调整控件的多个属性。The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. 例如,通常会调用SuspendLayout方法,然后设置SizeLocationAnchor,或Dock的控件,然后调用属性ResumeLayout方法,以使更改生效。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.

必须有未挂起调用SuspendLayoutResumeLayout成功调用。There must be no pending calls to SuspendLayout for ResumeLayout to be successfully called.

备注

当将多个控件添加到父控件,建议您调用SuspendLayout方法,然后再初始化要添加的控件。When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. 将控件添加到父控件之后, 调用ResumeLayout方法。After adding the controls to the parent control, call the ResumeLayout method. 这将提高具有多个控件的应用程序的性能。This will increase the performance of applications with many controls.

适用于

另请参阅