LayoutEngine.Layout メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Overridable Function Layout ( _ container As Object, _ layoutEventArgs As LayoutEventArgs _ ) As Boolean
Dim instance As LayoutEngine Dim container As Object Dim layoutEventArgs As LayoutEventArgs Dim returnValue As Boolean returnValue = instance.Layout(container, layoutEventArgs)
戻り値
container の親で再度レイアウト操作を実行する必要がある場合は true。それ以外の場合は false。


このメソッドは、レイアウト エンジンが container パラメータでレイアウト操作を実行するときに呼び出されます。layoutEventArgs の AffectedProperty、AffectedComponent、および AffectedControl の各プロパティの値を確認すると、レイアウト操作が必要かどうかを判断できます。
継承時の注意 カスタム レイアウト動作を提供するには Layout メソッドをオーバーライドします。 container パラメータのコンテンツをレイアウトする場合は、各子コントロールの Visible プロパティを確認する必要があります。 レイアウト エンジンのロジックが、コンテナの親でレイアウト操作を再度実行する必要があると判断すると true が返されます。これは、たとえばレイアウト エンジンが子コントロールのサイズを変更し、新しいレイアウトを収容するためにコンテナのサイズを大きくする必要があると判断したときに発生する場合があります。
Layout メソッドを使用してカスタム レイアウト動作を実装する方法を示すコード例を次に示します。このコード例は、LayoutEngine クラスのトピックで取り上げているコード例の一部分です。
Public Overrides Function Layout( _ ByVal container As Object, _ ByVal layoutEventArgs As LayoutEventArgs) As Boolean Dim parent As Control = container ' Use DisplayRectangle so that parent.Padding is honored. Dim parentDisplayRectangle As Rectangle = parent.DisplayRectangle Dim nextControlLocation As Point = parentDisplayRectangle.Location Dim c As Control For Each c In parent.Controls ' Only apply layout to visible controls. If c.Visible <> True Then Continue For End If ' Respect the margin of the control: ' shift over the left and the top. nextControlLocation.Offset(c.Margin.Left, c.Margin.Top) ' Set the location of the control. c.Location = nextControlLocation ' Set the autosized controls to their ' autosized heights. If c.AutoSize Then c.Size = c.GetPreferredSize(parentDisplayRectangle.Size) End If ' Move X back to the display rectangle origin. nextControlLocation.X = parentDisplayRectangle.X ' Increment Y by the height of the control ' and the bottom margin. nextControlLocation.Y += c.Height + c.Margin.Bottom Next c ' Optional: Return whether or not the container's ' parent should perform layout as a result of this ' layout. Some layout engines return the value of ' the container's AutoSize property. Return False End Function
public override bool Layout( object container, LayoutEventArgs layoutEventArgs) { Control parent = container as Control; // Use DisplayRectangle so that parent.Padding is honored. Rectangle parentDisplayRectangle = parent.DisplayRectangle; Point nextControlLocation = parentDisplayRectangle.Location; foreach (Control c in parent.Controls) { // Only apply layout to visible controls. if (!c.Visible) { continue; } // Respect the margin of the control: // shift over the left and the top. nextControlLocation.Offset(c.Margin.Left, c.Margin.Top); // Set the location of the control. c.Location = nextControlLocation; // Set the autosized controls to their // autosized heights. if (c.AutoSize) { c.Size = c.GetPreferredSize(parentDisplayRectangle.Size); } // Move X back to the display rectangle origin. nextControlLocation.X = parentDisplayRectangle.X; // Increment Y by the height of the control // and the bottom margin. nextControlLocation.Y += c.Height + c.Margin.Bottom; } // Optional: Return whether or not the container's // parent should perform layout as a result of this // layout. Some layout engines return the value of // the container's AutoSize property. return false; }
public: virtual bool Layout(Object^ container, LayoutEventArgs^ layoutEventArgs) override { Control^ parent = nullptr; try { parent = (Control ^) container; } catch (InvalidCastException^ ex) { throw gcnew ArgumentException( "The parameter 'container' must be a control", "container", ex); } // Use DisplayRectangle so that parent.Padding is honored. Rectangle parentDisplayRectangle = parent->DisplayRectangle; Point nextControlLocation = parentDisplayRectangle.Location; for each (Control^ currentControl in parent->Controls) { // Only apply layout to visible controls. if (!currentControl->Visible) { continue; } // Respect the margin of the control: // shift over the left and the top. nextControlLocation.Offset(currentControl->Margin.Left, currentControl->Margin.Top); // Set the location of the control. currentControl->Location = nextControlLocation; // Set the autosized controls to their // autosized heights. if (currentControl->AutoSize) { currentControl->Size = currentControl->GetPreferredSize( parentDisplayRectangle.Size); } // Move X back to the display rectangle origin. nextControlLocation.X = parentDisplayRectangle.X; // Increment Y by the height of the control // and the bottom margin. nextControlLocation.Y += currentControl->Height + currentControl->Margin.Bottom; } // Optional: Return whether or not the container's // parent should perform layout as a result of this // layout. Some layout engines return the value of // the container's AutoSize property. return false; }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


LayoutEngine クラス
LayoutEngine メンバ
System.Windows.Forms.Layout 名前空間
LayoutEventArgs
その他の技術情報
方法 : カスタム レイアウト エンジンを実装する
- LayoutEngine.Layout メソッドのページへのリンク