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. 此範例使用 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 方法,然後設定控制項的 [Size]、[Location]、[Anchor] 或 [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.

必須有 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.

適用於

另請參閱