Control.SuspendLayout 方法

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub SuspendLayout
用法
Dim instance As Control

instance.SuspendLayout
public void SuspendLayout ()
public:
void SuspendLayout ()
public void SuspendLayout ()
public function SuspendLayout ()

备注

控件的布局逻辑被挂起,直到调用 ResumeLayout 方法为止。

当调整控件的多个属性时,将先后使用 SuspendLayoutResumeLayout 方法取消多个 Layout 事件。例如,通常先调用 SuspendLayout 方法,然后设置控件的 SizeLocationAnchorDock 属性,最后调用 ResumeLayout 方法以使更改生效。

SuspendLayout 调用必须等于零,然后才能成功调用 ResumeLayout

提示

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

示例

下面的代码示例向窗体添加两个按钮。该示例通过使用 SuspendLayoutResumeLayout 方法进行添加按钮。

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
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:
   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.set_Location(new Point(10, 10));
    buttonOK.set_Size(new Size(75, 25));
    buttonOK.set_Text("OK");

    Button buttonCancel = new Button();
    buttonCancel.set_Location(new Point(90, 10));
    buttonCancel.set_Size(new Size(75, 25));
    buttonCancel.set_Text("Cancel");

    this.get_Controls().AddRange(new Control[] {buttonOK, buttonCancel});
    this.ResumeLayout();
} //AddButtons

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
ResumeLayout
LayoutEngine
Layout
PerformLayout
SuspendLayout
InitLayout