Control.Layout 事件

定義

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

C#
public event System.Windows.Forms.LayoutEventHandler Layout;
C#
public event System.Windows.Forms.LayoutEventHandler? Layout;

事件類型

範例

下列程式碼範例 Form 會在事件中將 置中畫面上 Layout 。 這會讓使用者調整大小時將表單置中。 此範例會要求您已建立 Form 控制項。

C#
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);	
}

備註

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

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱