Control.Layout 事件

定義

發生於控制項應重新調整其子控制項位置時。

public:
 event System::Windows::Forms::LayoutEventHandler ^ Layout;
public 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 。 這會讓使用者調整大小時將表單置中。 此範例會要求您已建立 Form 控制項。

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 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當新增或移除子控制項、控制項界限變更,以及發生可能會影響控制項配置的其他變更時,就會發生此事件。 配置事件可以使用 和 ResumeLayout 方法來隱藏 SuspendLayout 。 暫停版面配置可讓您在控制項上執行多個動作,而不需要針對每個變更執行版面配置。 例如,如果您調整控制項大小並移動控制項,則每個作業都會引發 Layout 事件。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱