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 方法。 这将提高具有许多控件的应用程序的性能。

适用于

另请参阅