Control.SuspendLayout 方法

定义

临时挂起控件的布局逻辑。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. 该示例通过使用和方法来事务添加按钮 SuspendLayout ResumeLayoutThe 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

注解

在调用方法之前,将挂起控件的布局逻辑 ResumeLayoutThe layout logic of the control is suspended until the ResumeLayout method is called.

SuspendLayout ResumeLayoutLayout 您调整控件的多个属性时,和方法在一起使用以取消多个事件。The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control. 例如,你通常会调用 SuspendLayout 方法,然后设置 Size 控件的、 LocationAnchorDock 属性,然后调用 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.

SuspendLayout对于要成功调用的,不能有任何挂起的调用 ResumeLayoutThere 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.

适用于

另请参阅