Control.Layout 事件

在控件应重新定位其子控件时发生。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Event Layout As LayoutEventHandler
用法
Dim instance As Control
Dim handler As LayoutEventHandler

AddHandler instance.Layout, handler
public event LayoutEventHandler Layout
public:
event LayoutEventHandler^ Layout {
    void add (LayoutEventHandler^ value);
    void remove (LayoutEventHandler^ value);
}
/** @event */
public void add_Layout (LayoutEventHandler value)

/** @event */
public void remove_Layout (LayoutEventHandler value)
JScript 支持使用事件,但不支持进行新的声明。

备注

在添加或移除子控件,控件的边界改变,以及在发生其他可影响控件布局的变化时,会发生 Layout 事件。可以使用 SuspendLayoutResumeLayout 方法取消布局事件。通过挂起布局,可以在控件上执行多个操作,而无需为每次更改执行一次布局操作。例如,如果调整控件大小和移动控件,每次操作都会引发 Layout 事件。

有关处理事件的更多信息,请参见 使用事件

示例

下面的代码示例在 Layout 事件中将 Form 在屏幕上居中。这将使该窗体在用户调整其大小时始终保持居中。此示例要求已经创建了一个 Form 控件。

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
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 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).get_Width() 
        / 2 - this.get_Width() / 2, Screen.GetBounds(this).get_Height() 
        / 2 - this.get_Height() / 2, this.get_Width(), this.get_Height(), 
        BoundsSpecified.Location);
} //MyForm_Layout

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
OnLayout
InitLayout
SuspendLayout
ResumeLayout
Control.LayoutEngine 属性
Control.Layout 事件
PerformLayout