Control.Layout Control.Layout Control.Layout Control.Layout Event


在控件应重新定位其子控件时发生。Occurs when a control should reposition its child controls.

 event System::Windows::Forms::LayoutEventHandler ^ Layout;
public event System.Windows.Forms.LayoutEventHandler Layout;
member this.Layout : System.Windows.Forms.LayoutEventHandler 
Public Custom Event Layout As LayoutEventHandler 


下面的代码示例在Form Layout事件的屏幕上居中。The following code example centers a Form on the screen in the Layout event. 这会使窗体在用户调整其大小时保持居中。This will keep the form centered as the user resizes it. 此示例要求您已经创建了一个Form控件。This example requires that you have created a Form control.

   void MyForm_Layout( Object^ /*sender*/, System::Windows::Forms::LayoutEventArgs^ /*e*/ )
      // Center the Form on the user's screen everytime it requires a Layout.
      this->SetBounds( (Screen::GetBounds( this ).Width / 2) - (this->Width / 2), (Screen::GetBounds( this ).Height / 2) - (this->Height / 2), this->Width, this->Height, BoundsSpecified::Location );
private void MyForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
   // Center the Form on the user's screen everytime it requires a Layout.
   this.SetBounds((Screen.GetBounds(this).Width/2) - (this.Width/2),
       (Screen.GetBounds(this).Height/2) - (this.Height/2),
       this.Width, this.Height, BoundsSpecified.Location);	

Private Sub MyForm_Layout(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout

    ' Center the Form on the user's screen everytime it requires a Layout.
    Me.SetBounds((System.Windows.Forms.Screen.GetBounds(Me).Width / 2) - (Me.Width / 2), _
        (System.Windows.Forms.Screen.GetBounds(Me).Height / 2) - (Me.Height / 2), _
        Me.Width, Me.Height, System.Windows.Forms.BoundsSpecified.Location)
End Sub


Layout添加或移除子控件、当控件的边界发生更改时,以及当发生其他可能会影响控件布局的更改时,将发生此事件。The Layout event occurs when child controls are added or removed, when the bounds of the control changes, and when other changes occur that can affect the layout of the control. 可以使用SuspendLayoutResumeLayout方法取消布局事件。The layout event can be suppressed using the SuspendLayout and ResumeLayout methods. 暂停布局使你可以对控件执行多个操作,而无需对每个更改执行布局。Suspending layout enables you to perform multiple actions on a control without having to perform a layout for each change. 例如,如果调整控件大小和移动控件,每个操作都将引发Layout一个事件。For example, if you resize and move a control, each operation would raise a Layout event.

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.