共用方式為


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 方法,然後設定 Size 控制項的 、 LocationAnchorDock 屬性,然後呼叫 ResumeLayout 方法,讓變更生效。

必須沒有任何擱置的 SuspendLayoutResumeLayout 呼叫,才能成功呼叫。

注意

將數個控制項加入父控制項時,建議您先呼叫 SuspendLayout 方法,再初始化要加入的控制項。 將控制項新增至父控制項之後,請呼叫 ResumeLayout 方法。 這會增加具有許多控制項的應用程式效能。

適用於

另請參閱