Control.Layout 事件


發生於控制項應重新調整其子控制項位置時。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 


下列程式碼範例會在 Layout 事件的畫面上將 Form 置中。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.