Control.Layout 事件
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於控制項應重新調整其子控制項位置時。
public:
event System::Windows::Forms::LayoutEventHandler ^ Layout;
C#
public event System.Windows.Forms.LayoutEventHandler Layout;
C#
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 );
}
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);
}
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 事件。
如需處理事件的詳細資訊,請參閱 處理和引發事件。
產品 | 版本 |
---|---|
.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 |