LayoutEngine.Layout(Object, LayoutEventArgs) 메서드

정의

레이아웃 엔진이 레이아웃 작업을 수행하라는 요청입니다.

public:
 virtual bool Layout(System::Object ^ container, System::Windows::Forms::LayoutEventArgs ^ layoutEventArgs);
public virtual bool Layout(object container, System.Windows.Forms.LayoutEventArgs layoutEventArgs);
abstract member Layout : obj * System.Windows.Forms.LayoutEventArgs -> bool
override this.Layout : obj * System.Windows.Forms.LayoutEventArgs -> bool
Public Overridable Function Layout (container As Object, layoutEventArgs As LayoutEventArgs) As Boolean

매개 변수

container
Object

레이아웃 엔진이 작동할 컨테이너입니다.

layoutEventArgs
LayoutEventArgs

이벤트의 이벤트 인수입니다 Layout .

반품

의 부모가 레이아웃을 다시 수행해야 하면 그렇지 않으면 .

예외

container 은 레이아웃을 수행할 수 있는 형식이 LayoutEngine 아닙니다.

예제

다음 코드 예제에서는 메서드를 사용하여 Layout 사용자 지정 레이아웃 동작을 구현하는 방법을 보여 줍니다. 이 코드 예제는 클래스에 제공된 더 큰 예제의 LayoutEngine 일부입니다.

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;
    }
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 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

설명

이 메서드는 레이아웃 엔진이 매개 변수에 대해 container 레이아웃 작업을 수행할 때 호출됩니다. 레이아웃 작업이 필요한지 여부를 결정하기 위해 , AffectedPropertyAffectedComponent 속성 AffectedControllayoutEventArgs값을 확인할 수 있습니다.

상속자 참고

사용자 지정 레이아웃 동작을 제공하도록 메서드를 재정의 Layout(Object, LayoutEventArgs) 합니다.

매개 변수의 container 내용을 배치할 때 각 자식 컨트롤의 Visible 속성을 확인해야 합니다.

레이아웃 엔진 논리가 컨테이너의 부모에 의해 레이아웃을 다시 수행해야 한다고 결정하는 경우 반환 true 합니다. 예를 들어 레이아웃 엔진이 자식 컨트롤의 크기를 조정하고 새 레이아웃을 수용하기 위해 컨테이너 크기를 늘려야 한다고 결정할 때 발생할 수 있습니다.

적용 대상

추가 정보