Control.Layout 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當控制項應該重新定位其子控制項時,會發生這種情況。
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
事件類型
範例
以下程式碼範例將事件中 a 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當子控制項被新增或移除、控制項的界限改變,以及其他可能影響控制項配置的變更時,就會發生該事件。 layout SuspendLayout 事件可以用 and ResumeLayout 方法來抑制。 暫停版面功能讓你能對一個控制器執行多個操作,而不必每次都做版面。 例如,如果你調整大小並移動一個控制項,每個操作都會觸發一個 Layout 事件。
如需處理事件的詳細資訊,請參閱 處理和引發事件。