내보내기(0) 인쇄
모두 확장
이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
번역
원본

LayoutSettings 클래스

레이아웃 구성표 특징을 수집에 대 한 기본 클래스를 제공 합니다.

네임스페이스:  System.Windows.Forms
어셈블리:  System.Windows.Forms(System.Windows.Forms.dll)

public abstract class LayoutSettings

LayoutSettings 형식에서는 다음과 같은 멤버를 노출합니다.

  이름설명
Protected 메서드LayoutSettings새 인스턴스 초기화를 LayoutSettings 클래스입니다.
위쪽

  이름설명
Public 속성LayoutEngine현재 테이블 레이아웃 엔진을 가져옵니다.
위쪽

  이름설명
Public 메서드Equals(Object) 지정한 개체가 현재 개체와 같은지 여부를 확인합니다. (Object에서 상속됨)
Protected 메서드Finalize 개체가 가비지 수집자에서 회수되기 전에, 해당 개체에서 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다. (Object에서 상속됨)
Public 메서드GetHashCode기본 해시 함수로 작동합니다. (Object에서 상속됨)
Public 메서드GetType현재 인스턴스의 Type을 가져옵니다. (Object에서 상속됨)
Protected 메서드MemberwiseClone현재 Object의 단순 복사본을 만듭니다. (Object에서 상속됨)
Public 메서드ToString현재 개체를 나타내는 문자열을 반환합니다. (Object에서 상속됨)
위쪽

LayoutSettings 클래스는 다양 한 일반적인 특성 특정 사용자 인터페이스 (UI) 레이아웃 구성표에 collect 유형에 대 한 기본 클래스 TableLayoutSettingsFlowLayoutSettings.

다음은 초기화 하는 방법을 보여 줍니다.는 TableLayoutSettings 에 대 한 개체는 TableLayoutPanel 컨트롤입니다. 에 대 한 전체 코드 샘플을 참조 하십시오. 방법: 사용자 지정 ToolStripRenderer 구현.


// The following class implements a sliding-tile puzzle.
// The GridStrip control is a custom ToolStrip that arranges
// its ToolStripButton controls in a grid layout. There is 
// one empty cell, into which the user can slide an adjacent
// tile with a drag-and-drop operation. Tiles that are eligible 
// for moving are highlighted.
public class GridStrip : ToolStrip
{
    // The button that is the drag source.
    private ToolStripButton dragButton = null;

    // Settings for the ToolStrip control's TableLayoutPanel.
    // This provides access to the cell position of each
    // ToolStripButton.
    private TableLayoutSettings tableSettings = null;

    // The empty cell. ToolStripButton controls that are
    // adjacent to this button can be moved to this button's
    // cell position.
    private ToolStripButton emptyCellButton = null;

    // The dimensions of each tile. A tile is represented
    // by a ToolStripButton controls.
    private Size tileSize = new Size(128, 128);

    // The number of rows in the GridStrip control.
    private readonly int rows = 5;

    // The number of columns in the GridStrip control.
    private readonly int columns = 5;

    // The one-time initialzation behavior is enforced
    // with this field. For more information, see the 
    // OnPaint method.
    private bool firstTime = false;

    // This is a required by the Windows Forms designer.
    private System.ComponentModel.IContainer components;

    // The default constructor.  
    public GridStrip()
    {
        this.InitializeComponent();

        this.InitializeTableLayoutSettings();
    }

    // This property exposes the empty cell to the 
    // GridStripRenderer class.
    internal ToolStripButton EmptyCell
    {
        get
        {
            return this.emptyCellButton;
        }
    }

    // This utility method initializes the TableLayoutPanel 
    // which contains the ToolStripButton controls.
    private void InitializeTableLayoutSettings()
    {
        // Specify the numbers of rows and columns in the GridStrip control.
        this.tableSettings = base.LayoutSettings as TableLayoutSettings;
        this.tableSettings.ColumnCount = this.rows;
        this.tableSettings.RowCount = this.columns;

        // Create a dummy bitmap with the dimensions of each tile.
        // The GridStrip control sizes itself based on these dimensions.
        Bitmap b = new Bitmap(tileSize.Width, tileSize.Height);

        // Populate the GridStrip control with ToolStripButton controls.
        for (int i = 0; i < this.tableSettings.ColumnCount; i++)
        {
            for (int j = 0; j < this.tableSettings.RowCount; j++)
            {
                // Create a new ToolStripButton control.
                ToolStripButton btn = new ToolStripButton();
                btn.DisplayStyle = ToolStripItemDisplayStyle.Image;
                btn.Image = b;
                btn.ImageAlign = ContentAlignment.MiddleCenter;
                btn.ImageScaling = ToolStripItemImageScaling.None;
                btn.Margin = Padding.Empty;
                btn.Padding = Padding.Empty;

                // Add the new ToolStripButton control to the GridStrip.
                this.Items.Add(btn);

                // Set the cell position of the ToolStripButton control.
                TableLayoutPanelCellPosition cellPos = new TableLayoutPanelCellPosition(i, j);
                this.tableSettings.SetCellPosition(btn, cellPos);

                // If this is the ToolStripButton control at cell (0,0),
                // assign it as the empty cell button.
                if( i == 0 && j == 0 )
                {
                    btn.Text = "Empty Cell";
                    btn.Image = b;
                    this.emptyCellButton = btn;
                }
            }
        }
    }

    // This method defines the Paint event behavior.
    // The GridStripRenderer requires that the GridStrip
    // be fully layed out when it is renders, so this
    // initialization code cannot be placed in the
    // GridStrip constructor. By the time the Paint
    // event is raised, the control layout has been 
    // completed, so the GridStripRenderer can paint
    // correctly. This one-time initialization is
    // implemented with the firstTime field.
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        if (!this.firstTime)
        {
            this.Renderer = new GridStripRenderer();

            // Comment this line to see the unscrambled image.
            this.ScrambleButtons();
            this.firstTime = true;
        }
    }

    // This utility method changes the ToolStripButton control 
    // positions in the TableLayoutPanel. This scrambles the 
    // buttons to initialize the puzzle.
    private void ScrambleButtons()
    {
        int i = 0;
        int lastElement = this.Items.Count - 1;

        while ( (i != lastElement ) &&
                (lastElement - i > 1) )
        {
            TableLayoutPanelCellPosition pos1 = 
                this.tableSettings.GetCellPosition(this.Items[i]);

            TableLayoutPanelCellPosition pos2 = 
                this.tableSettings.GetCellPosition(this.Items[lastElement]);

            this.tableSettings.SetCellPosition(
                this.Items[i++], 
                pos2);

            this.tableSettings.SetCellPosition(
                this.Items[lastElement--], 
                pos1);
        }
    }

    // This method defines the MouseDown event behavior. 
    // If the user has clicked on a valid drag source, 
    // the drag operation starts.
    protected override void OnMouseDown(MouseEventArgs mea)
    {
        base.OnMouseDown(mea);

        ToolStripButton btn = this.GetItemAt(mea.Location) as ToolStripButton;

        if (btn != null)
        {
            if (this.IsValidDragSource(btn))
            {
                this.dragButton = btn;
            }
        }
    }

    // This method defines the MouseMove event behavior. 
    protected override void OnMouseMove(MouseEventArgs mea)
    {
        base.OnMouseMove(mea);

        // Is a drag operation pending?
        if (this.dragButton != null)
        {
            // A drag operation is pending. Call DoDragDrop to 
            // determine the disposition of the operation.
            DragDropEffects dropEffect = this.DoDragDrop(
                new DataObject(this.dragButton), 
                DragDropEffects.Move);
        }
    }

    // This method defines the DragOver event behavior. 
    protected override void OnDragOver(DragEventArgs dea)
    {
        base.OnDragOver(dea);

        // Get the ToolStripButton control 
        // at the given mouse position.
        Point p = new Point(dea.X, dea.Y);
        ToolStripButton item = this.GetItemAt(
            this.PointToClient(p)) as ToolStripButton;

        // If the ToolStripButton control is the empty cell,
        // indicate that the move operation is valid.
        if( item == this.emptyCellButton )
        {
            // Set the drag operation to indicate a valid move.
            dea.Effect = DragDropEffects.Move;
        }
    }

    // This method defines the DragDrop event behavior. 
    protected override void OnDragDrop(DragEventArgs dea)
    {
        base.OnDragDrop(dea);

        // Did a valid move operation occur?
        if (dea.Effect == DragDropEffects.Move)
        {
            // The move operation is valid. Adjust the state
            // of the GridStrip control's TableLayoutPanel,
            // by swapping the positions of the source button
            // and the empty cell button.

            // Get the cell of the control to move.
            TableLayoutPanelCellPosition sourcePos = 
                tableSettings.GetCellPosition(this.dragButton);

            // Get the cell of the emptyCellButton.
            TableLayoutPanelCellPosition dropPos = 
                tableSettings.GetCellPosition(this.emptyCellButton);

            // Move the control to the empty cell.
            tableSettings.SetCellPosition(this.dragButton, dropPos);

            // Set the position of the empty cell to 
            // that of the previously occupied cell.
            tableSettings.SetCellPosition(this.emptyCellButton, sourcePos);

            // Reset the drag operation.
            this.dragButton = null;
        }
    }

    // This method defines the DragLeave event behavior. 
    // If the mouse leaves the client area of the GridStrip
    // control, the drag operation is canceled.
    protected override void OnDragLeave(EventArgs e)
    {
        base.OnDragLeave(e);

        // Reset the drag operation.
        this.dragButton = null;
    }

    // This method defines the ueryContinueDrag event behavior. 
    // If the mouse leaves the client area of the GridStrip
    // control, the drag operation is canceled.
    protected override void OnQueryContinueDrag(QueryContinueDragEventArgs qcdevent)
    {
        base.OnQueryContinueDrag(qcdevent);

        // Get the current mouse position, in screen coordinates.
        Point mousePos = this.PointToClient(Control.MousePosition);

        // If the mouse position is outside the GridStrip control's
        // client area, cancel the drag operation. Be sure to
        // transform the mouse's screen coordinates to client coordinates. 
        if (!this.ClientRectangle.Contains(mousePos))
        {
            qcdevent.Action = DragAction.Cancel;
        }
    }

    // This utility method determines if a button
    // is positioned relative to the empty cell 
    // such that it can be dragged into the empty cell.
    private bool IsValidDragSource(ToolStripButton b)
    {
        TableLayoutPanelCellPosition sourcePos = 
            tableSettings.GetCellPosition(b);

        TableLayoutPanelCellPosition emptyPos = 
            tableSettings.GetCellPosition(this.emptyCellButton);

        return (IsValidDragSource(sourcePos, emptyPos));
    }

    // This utility method determines if a cell position
    // is adjacent to the empty cell.
    internal static bool IsValidDragSource(
        TableLayoutPanelCellPosition sourcePos, 
        TableLayoutPanelCellPosition emptyPos)
    {
        bool returnValue = false;

        // A cell is considered to be a valid drag source if it
        // is adjacent to the empty cell. Cells that are positioned
        // on a diagonal are not valid.
        if (((sourcePos.Column == emptyPos.Column - 1) && (sourcePos.Row == emptyPos.Row)) ||
            ((sourcePos.Column == emptyPos.Column + 1) && (sourcePos.Row == emptyPos.Row)) ||
            ((sourcePos.Column == emptyPos.Column) && (sourcePos.Row == emptyPos.Row - 1)) ||
            ((sourcePos.Column == emptyPos.Column) && (sourcePos.Row == emptyPos.Row + 1)))
        {
            returnValue = true;
        }

        return returnValue;
    }


.NET Framework

4.5, 4, 3.5, 3.0, 2.0에서 지원

.NET Framework Client Profile

4, 3.5 SP1에서 지원

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(서버 코어 역할은 지원되지 않음), Windows Server 2008 R2(서버 코어 역할은 SP1 이상에서 지원, Itanium은 지원되지 않음)

.NET Framework 에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 다음을 참조하십시오. .NET Framework 시스템 요구 사항.

이 형식의 static(Visual Basic의 경우 Shared) 모든 공용 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
표시:
© 2014 Microsoft