LayoutEngine.Layout メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > LayoutEngine.Layout メソッドの意味・解説 

LayoutEngine.Layout メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

レイアウト エンジンレイアウト操作実行要求します

名前空間: System.Windows.Forms.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)
public virtual bool Layout (
    Object container,
    LayoutEventArgs layoutEventArgs
)
public:
virtual bool Layout (
    Object^ container, 
    LayoutEventArgs^ layoutEventArgs
)
public boolean Layout (
    Object container, 
    LayoutEventArgs layoutEventArgs
)
public function Layout (
    container : Object, 
    layoutEventArgs : LayoutEventArgs
) : boolean

パラメータ

container

レイアウト エンジン操作を行うコンテナ

layoutEventArgs

Layout イベントからのイベント引数

戻り値
container の親で再度レイアウト操作実行する必要がある場合trueそれ以外場合false

例外例外
例外種類条件

NotSupportedException

container は、LayoutEngineレイアウト実行できる型ではありません。

解説解説
使用例使用例

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;
    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

LayoutEngine.Layout メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



LayoutEngine.Layout メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS