Control.Layout イベント
コントロールの子コントロールの位置を変更する必要があるときに発生します。
Public Event Layout As LayoutEventHandler
[C#]
public event LayoutEventHandler Layout;
[C++]
public: __event LayoutEventHandler* Layout;
[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。
イベント データ
イベント ハンドラが、このイベントに関連するデータを含む、LayoutEventArgs 型の引数を受け取りました。次の LayoutEventArgs プロパティには、このイベントの固有の情報が記載されます。
プロパティ | 説明 |
---|---|
AffectedControl | 変更により影響を受けた子コントロールを取得します。 |
AffectedProperty | 変更により影響を受けたプロパティを取得します。 |
解説
Layout イベントは、子コントロールが追加または削除されるとき、コントロールの境界が変更されるとき、およびコントロールのレイアウトに影響を与える可能性があるその他の変化が発生するときに発生します。レイアウト イベントは、 SuspendLayout メソッドおよび ResumeLayout メソッドを使用して中止できます。レイアウトを中断すると、各変更に対してレイアウトを実行しなくても、コントロールで複数のアクションを実行できます。たとえば、コントロールのサイズを変更して移動する場合は、各操作で Layout イベントが発生します。
イベント処理の詳細については、「 イベントの利用 」を参照してください。
使用例
[Visual Basic, C#, C++] 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
[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);
}
[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);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
Control クラス | Control メンバ | System.Windows.Forms 名前空間 | OnLayout | InitLayout | SuspendLayout | ResumeLayout