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.