Control.SuspendLayout 方法

定义

临时挂起控件的布局逻辑。

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

示例

下面的代码示例向窗体添加两个按钮。 该示例使用 SuspendLayoutResumeLayout 方法处理添加按钮。

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 ,控件的布局逻辑将暂停。

在调整控件的多个属性时,这些 SuspendLayoutResumeLayout 方法用于抑制多个 Layout 事件。 例如,通常 SuspendLayout 调用该方法,然后设置控件的 SizeLocationAnchorDock 属性,然后调用 ResumeLayout 该方法以使更改生效。

必须没有要成功调用的挂起调用SuspendLayoutResumeLayout

备注

将多个控件添加到父控件时,建议在初始化要添加的控件之前调用 SuspendLayout 该方法。 将控件添加到父控件后,调用 ResumeLayout 该方法。 这将提高具有许多控件的应用程序的性能。

适用于

另请参阅