예제 #1
0
        public void TableLayoutPanel_GrowStyle_Set_GetReturnsExpected(TableLayoutPanelGrowStyle value)
        {
            var panel = new TableLayoutPanel
            {
                GrowStyle = value
            };

            Assert.Equal(value, panel.GrowStyle);
        }
예제 #2
0
 public ContainerInfo(ContainerInfo containerInfo)
 {
     _cellBorderWidth = containerInfo.CellBorderWidth;
     _maxRows         = containerInfo.MaxRows;
     _maxColumns      = containerInfo.MaxColumns;
     _growStyle       = containerInfo.GrowStyle;
     _container       = containerInfo.Container;
     _rowStyles       = containerInfo.RowStyles;
     _colStyles       = containerInfo.ColumnStyles;
 }
        public void TableLayoutSettings_GrowStyle_Set_GetReturnsExpected(TableLayoutPanelGrowStyle value)
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            settings.GrowStyle = value;
            Assert.Equal(value, settings.GrowStyle);
        }
예제 #4
0
        public void TableLayoutPanel_GetRowHeights_InvokeNoChildren_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle
            };

            Assert.Equal(new int[] { 0, 100 }, panel.GetRowHeights());
        }
 internal TableLayoutSettings(IArrangedContainer panel)
 {
     this.column_styles = new TableLayoutColumnStyleCollection(panel);
     this.row_styles    = new TableLayoutRowStyleCollection(panel);
     this.grow_style    = TableLayoutPanelGrowStyle.AddRows;
     this.column_count  = 0;
     this.row_count     = 0;
     this.columns       = new Dictionary <object, int> ();
     this.column_spans  = new Dictionary <object, int> ();
     this.rows          = new Dictionary <object, int> ();
     this.row_spans     = new Dictionary <object, int> ();
     this.panel         = panel;
 }
예제 #6
0
		internal TableLayoutSettings (TableLayoutPanel panel)
		{
			this.column_styles = new TableLayoutColumnStyleCollection (panel);
			this.row_styles = new TableLayoutRowStyleCollection (panel);
			this.grow_style = TableLayoutPanelGrowStyle.AddRows;
			this.column_count = 0;
			this.row_count = 0;
			this.columns = new Dictionary<object, int> ();
			this.column_spans = new Dictionary<object, int> ();
			this.rows = new Dictionary<object, int> ();
			this.row_spans = new Dictionary<object, int> ();
			this.panel = panel;
		}
예제 #7
0
		private TableLayoutSettings (SerializationInfo serializationInfo, StreamingContext context)
		{
			TypeConverter converter = TypeDescriptor.GetConverter (this);
			string text = serializationInfo.GetString ("SerializedString");
			if (!string.IsNullOrEmpty (text) && (converter != null)) {
				TableLayoutSettings settings = converter.ConvertFromInvariantString (text) as TableLayoutSettings;
				this.column_styles = settings.column_styles;
				this.row_styles = settings.row_styles;
				this.grow_style = settings.grow_style;
				this.column_count = settings.column_count;
				this.row_count = settings.row_count;
				this.columns = settings.columns;
				this.column_spans = settings.column_spans;
				this.rows = settings.rows;
				this.row_spans = settings.row_spans;
				this.panel = settings.panel;
				this.isSerialized = true;
			}
		}
 internal TableLayoutSettings(IArrangedContainer panel, TableLayoutSettings settings)
 {
     this.column_styles = new TableLayoutColumnStyleCollection(panel);
     this.row_styles    = new TableLayoutRowStyleCollection(panel);
     this.grow_style    = settings.grow_style;
     this.column_count  = settings.column_count;
     this.row_count     = settings.row_count;
     this.columns       = new Dictionary <object, int> (settings.columns);
     this.column_spans  = new Dictionary <object, int> (settings.column_spans);
     this.rows          = new Dictionary <object, int> (settings.rows);
     this.row_spans     = new Dictionary <object, int> (settings.row_spans);
     this.panel         = panel;
     foreach (ColumnStyle column_style in settings.column_styles)
     {
         this.column_styles.Add(new ColumnStyle(column_style.SizeType, column_style.Width));
     }
     foreach (RowStyle row_style in settings.row_styles)
     {
         this.row_styles.Add(new RowStyle(row_style.SizeType, row_style.Height));
     }
 }
        private TableLayoutSettings(SerializationInfo serializationInfo, StreamingContext context)
        {
            TypeConverter converter = TypeDescriptor.GetConverter(this);
            string        text      = serializationInfo.GetString("SerializedString");

            if (!string.IsNullOrEmpty(text) && (converter != null))
            {
                TableLayoutSettings settings = converter.ConvertFromInvariantString(text) as TableLayoutSettings;
                this.column_styles = settings.column_styles;
                this.row_styles    = settings.row_styles;
                this.grow_style    = settings.grow_style;
                this.column_count  = settings.column_count;
                this.row_count     = settings.row_count;
                this.columns       = settings.columns;
                this.column_spans  = settings.column_spans;
                this.rows          = settings.rows;
                this.row_spans     = settings.row_spans;
                this.panel         = settings.panel;
                this.isSerialized  = true;
            }
        }
예제 #10
0
 public ContainerInfo(IArrangedElement container) {
     _container = container;
     _growStyle = TableLayoutPanelGrowStyle.AddRows;
 }
예제 #11
0
        /// <devdoc>
        /// xAssignRowsAndColumns: part of AssignRowsAndColumns.
        ///   def: fixed element: has a specific row/column assignment (assigned by SetRow,SetColumn, or Add(c,row,column)
        ///   def: flow element: does NOT have a specific row/column assignment.
        ///
        ///   Determines the placement of fixed and flow elements.  Walks through the rows/columns - if there's a 
        ///   spot for the fixed element, place it, else place the next flow element.
        /// </devdoc>
        private bool xAssignRowsAndColumns(ContainerInfo containerInfo, LayoutInfo[] childrenInfo, int maxColumns, int maxRows, TableLayoutPanelGrowStyle growStyle) {
            Debug.Assert(maxColumns > 0, "maxColumn must be positive");
           
            int numColumns = 0;
            int numRows = 0;
            ReservationGrid reservationGrid = new ReservationGrid();
           
            int currentRow = 0;
            int currentCol = 0;

            int fixedElementIndex = -1;
            int flowElementIndex = -1;

            // make sure to snap these two collections as we're not in a "containerInfo.Valid" state
            // so we'll wind up building up the lists over and over again.          
            LayoutInfo[] fixedChildrenInfo = containerInfo.FixedChildrenInfo;
            
            
            //the element at the head of the absolutely positioned element queue
            LayoutInfo fixedElement = GetNextLayoutInfo(fixedChildrenInfo, ref fixedElementIndex, /*absolutelyPositioned*/true);
            
            //the element at the head of the non-absolutely positioned element queue
            LayoutInfo flowElement = GetNextLayoutInfo(childrenInfo, ref flowElementIndex, /*absolutelyPositioned*/false);
         
            while (fixedElement != null || flowElement != null) {

                int colStop = currentCol;
                int rowStop;
                if (flowElement != null) {
                    flowElement.RowStart = currentRow;
                    flowElement.ColumnStart = currentCol;
                    //try to layout the flowElement to see if it overlaps with the fixedElement
                    AdvanceUntilFits(maxColumns, reservationGrid, flowElement, out colStop);
                    //we have exceeded the row limit. just return
                    if (flowElement.RowStart >= maxRows) {
                        return false;
                    }
                }
                //test to see if either the absolutely positioned element is null or it fits. 
                if (flowElement != null && (fixedElement == null || (!IsCursorPastInsertionPoint(fixedElement, flowElement.RowStart, colStop) && !IsOverlappingWithReservationGrid(fixedElement, reservationGrid, currentRow)))) {                        
                    //Place the flow element.

                    //advance the rows in reservation grid
                    for (int j = 0; j < flowElement.RowStart - currentRow; j++) {
                        reservationGrid.AdvanceRow();
                    }
                    
                    currentRow = flowElement.RowStart;
                    rowStop = Math.Min(currentRow + flowElement.RowSpan, maxRows);
                    
                    //reserve spaces in the reservationGrid
                    reservationGrid.ReserveAll(flowElement, rowStop, colStop);
                    flowElement = GetNextLayoutInfo(childrenInfo, ref flowElementIndex, /*absolutelyPositioned*/false);
                }
                else {
                    //
                    //otherwise we place the fixed element.
                    //
                    if (currentCol >= maxColumns) {
                        //we have already passed the boundary. Go to next row
                        currentCol = 0;
                        currentRow++;
                        reservationGrid.AdvanceRow();
                    }
                    //set the rowStart and columnStart to fixedElement's specifed position
                    fixedElement.RowStart = Math.Min(fixedElement.RowPosition, maxRows - 1);
                    fixedElement.ColumnStart = Math.Min(fixedElement.ColumnPosition, maxColumns - 1);
                    if (currentRow > fixedElement.RowStart) {
                        //we have already passed the specifed position. set the start column to the current column
                        fixedElement.ColumnStart = currentCol;
                    }
                    else if (currentRow == fixedElement.RowStart) {
                        //set the start column to be the max of the specifed column and current column
                        fixedElement.ColumnStart = Math.Max(fixedElement.ColumnStart, currentCol);
                    }
                    else {
                        //set the start column to the specified column, which we have already done
                    }
                    fixedElement.RowStart = Math.Max(fixedElement.RowStart, currentRow);

                    //advance the reservation grid 
                    int j;
                    for (j = 0; j < fixedElement.RowStart - currentRow; j++) {
                        reservationGrid.AdvanceRow();
                    }

                    //try to layout the absolutely positioned element as if it were non-absolutely positioned.
                    //In this way we can tell whether this element overlapps with others or fits on the table.
                    AdvanceUntilFits(maxColumns, reservationGrid, fixedElement, out colStop);

                    //we have exceeded the row limit. just return
                    if (fixedElement.RowStart >= maxRows) {
                        return false;
                    }

                    for (; j < fixedElement.RowStart - currentRow; j++) {
                        //advance the reservation grid if the fixedElement's row position has changed during layout
                        reservationGrid.AdvanceRow();
                    }
                    currentRow = fixedElement.RowStart;
                    
                    //make sure that we truncate the element's column span if it is too big
                    colStop = Math.Min(fixedElement.ColumnStart + fixedElement.ColumnSpan, maxColumns); 
                    rowStop = Math.Min(fixedElement.RowStart + fixedElement.RowSpan, maxRows);             

                    //reserve space in the reservation grid
                    reservationGrid.ReserveAll(fixedElement, rowStop, colStop);    

                    fixedElement = GetNextLayoutInfo(fixedChildrenInfo, ref fixedElementIndex, /*absolutelyPositioned*/true);
                }               
                currentCol = colStop;
                numRows    = (numRows    == Int32.MaxValue) ? rowStop : Math.Max(numRows, rowStop);
                numColumns = (numColumns == Int32.MaxValue) ? colStop : Math.Max(numColumns, colStop);                     
            }  

            Debug.Assert(numRows <= maxRows, "number of rows allocated shouldn't exceed max number of rows");
            Debug.Assert(numColumns <= maxColumns, "number of columns allocated shouldn't exceed max number of columns");


            // we should respect columncount and rowcount as according to GrowStyle.
            if (growStyle == TableLayoutPanelGrowStyle.FixedSize) {
                // now that we've calculated the assignments - use the "max" as the actual number of rows.
                numColumns = maxColumns;
                numRows = maxRows;
            }
            else if (growStyle == TableLayoutPanelGrowStyle.AddRows) {
				numColumns = maxColumns;
				numRows = Math.Max(containerInfo.MaxRows, numRows);
            }
            else { // add columns
                numRows = (maxRows == Int32.MaxValue) ? numRows : maxRows;
                numColumns = Math.Max(containerInfo.MaxColumns, numColumns);
            }

            // PERF: prevent overallocation of Strip[] arrays.  We're going to null these guys out
            // anyways... so only allocate when the number of rows and columns is different.
            if (containerInfo.Rows == null || containerInfo.Rows.Length != numRows) {
                containerInfo.Rows = new Strip[numRows];
            }
            if (containerInfo.Columns == null || containerInfo.Columns.Length != numColumns) {
                containerInfo.Columns = new Strip[numColumns];
            }

            containerInfo.Valid = true;
            return true;

        }
예제 #12
0
        public void TableLayoutPanel_GetRowHeights_CustomInvalidStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(50, 50)
            };

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 22));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 22));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle((SizeType)(SizeType.AutoSize - 1), 6));
            Assert.Equal(new int[] { 0, 50 }, panel.GetRowHeights());
        }
예제 #13
0
        public void TableLayoutPanel_GetRowHeights_CustomStylesAbsoluteOverflow_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(70, 80)
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 100));
            Assert.Equal(new int[] { 100, 0 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 100));
            Assert.Equal(new int[] { 100, 100 }, panel.GetRowHeights());
        }
예제 #14
0
        public void TableLayoutPanel_GetRowHeights_CustomPercentStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle,
                ClientSize  = new Size(70, 80)
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 20));
            Assert.Equal(new int[] { 80, 0 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 30));
            Assert.Equal(new int[] { 32, 48 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 6));
            Assert.Equal(new int[] { 32, 48 }, panel.GetRowHeights());
        }
예제 #15
0
        public void TableLayoutPanel_GetRowHeights_CustomAbsoluteStyles_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle
            };

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 10));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 5));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());

            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 6));
            Assert.Equal(new int[] { 10, 90 }, panel.GetRowHeights());
        }
예제 #16
0
 public ContainerInfo(IArrangedElement container)
 {
     _container = container;
     _growStyle = TableLayoutPanelGrowStyle.AddRows;
 }
예제 #17
0
        public void TableLayoutPanel_GetColumnWidths_InvokeNoChildren_ReturnsExpected(TableLayoutPanelGrowStyle growStyle)
        {
            var control = new Button
            {
                Visible = true
            };
            var panel = new TableLayoutPanel
            {
                ColumnCount = 3,
                RowCount    = 2,
                GrowStyle   = growStyle
            };

            Assert.Equal(new int[] { 0, 0, 200 }, panel.GetColumnWidths());
        }
예제 #18
0
        public void TableLayoutPanel_GrowStyle_SetNegative_ThrowsArgumentOutOfRangeException(TableLayoutPanelGrowStyle value)
        {
            var panel = new TableLayoutPanel();

            Assert.Throws <ArgumentOutOfRangeException>("value", () => panel.GrowStyle = value);
        }
예제 #19
0
파일: form1.cs 프로젝트: ruo2012/samples-1
    // </snippet6>

    // <snippet7>
    private void growStyleNoneBtn_CheckedChanged(
        System.Object sender,
        System.EventArgs e)
    {
        this.tlpGrowStyle = TableLayoutPanelGrowStyle.FixedSize;
    }
예제 #20
0
 public ContainerInfo(ContainerInfo containerInfo) {
     _cellBorderWidth = containerInfo.CellBorderWidth;
     _maxRows = containerInfo.MaxRows;
     _maxColumns = containerInfo.MaxColumns;
     _growStyle = containerInfo.GrowStyle;
     _container = containerInfo.Container;
     _rowStyles = containerInfo.RowStyles;
     _colStyles = containerInfo.ColumnStyles;
 }
예제 #21
0
파일: form1.cs 프로젝트: ruo2012/samples-1
 private void growStyleAddColumnBtn_CheckedChanged(
     System.Object sender,
     System.EventArgs e)
 {
     this.tlpGrowStyle = TableLayoutPanelGrowStyle.AddColumns;
 }
        public void TableLayoutSettings_GrowStyle_SetNegative_ThrowsArgumentOutOfRangeException(TableLayoutPanelGrowStyle value)
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings settings = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);

            Assert.Throws <ArgumentOutOfRangeException>("value", () => settings.GrowStyle = value);
        }
예제 #23
0
        internal Control[,] CalculateControlPositions(TableLayoutPanel panel, int columns, int rows)
        {
            Control[,] grid = new Control[columns, rows];

            TableLayoutSettings settings = panel.LayoutSettings;

            // First place all controls that have an explicit col/row
            foreach (Control c in panel.Controls)
            {
                int col = settings.GetColumn(c);
                int row = settings.GetRow(c);
                if (col >= 0 && row >= 0)
                {
                    if (col >= columns)
                    {
                        return(CalculateControlPositions(panel, col + 1, rows));
                    }
                    if (row >= rows)
                    {
                        return(CalculateControlPositions(panel, columns, row + 1));
                    }

                    if (grid[col, row] == null)
                    {
                        int col_span = Math.Min(settings.GetColumnSpan(c), columns);
                        int row_span = Math.Min(settings.GetRowSpan(c), rows);

                        if (col + col_span > columns)
                        {
                            if (row + 1 < rows)
                            {
                                grid[col, row] = dummy_control;
                                row++;
                                col = 0;
                            }
                            else if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddColumns)
                            {
                                return(CalculateControlPositions(panel, columns + 1, rows));
                            }
                            else
                            {
                                throw new ArgumentException();
                            }
                        }

                        if (row + row_span > rows)
                        {
                            if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddRows)
                            {
                                return(CalculateControlPositions(panel, columns, rows + 1));
                            }
                            else
                            {
                                throw new ArgumentException();
                            }
                        }

                        grid[col, row] = c;

                        // Fill in the rest of this control's row/column extent with dummy
                        // controls, so that other controls don't get put there.
                        for (int i = 0; i < col_span; i++)
                        {
                            for (int j = 0; j < row_span; j++)
                            {
                                if (i != 0 || j != 0)
                                {
                                    grid[col + i, row + j] = dummy_control;
                                }
                            }
                        }
                    }
                }
            }

            int x_pointer = 0;
            int y_pointer = 0;

            // Fill in gaps with controls that do not have an explicit col/row
            foreach (Control c in panel.Controls)
            {
                int col = settings.GetColumn(c);
                int row = settings.GetRow(c);

                if ((col >= 0 && col < columns) && (row >= 0 && row < rows) && (grid[col, row] == c || grid[col, row] == dummy_control))
                {
                    continue;
                }

                for (int y = y_pointer; y < rows; y++)
                {
                    y_pointer = y;
                    x_pointer = 0;

                    for (int x = x_pointer; x < columns; x++)
                    {
                        x_pointer = x;

                        if (grid[x, y] == null)
                        {
                            int col_span = Math.Min(settings.GetColumnSpan(c), columns);
                            int row_span = Math.Min(settings.GetRowSpan(c), rows);

                            if (x + col_span > columns)
                            {
                                if (y + 1 < rows)
                                {
                                    break;
                                }
                                else if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddColumns)
                                {
                                    return(CalculateControlPositions(panel, columns + 1, rows));
                                }
                                else
                                {
                                    throw new ArgumentException();
                                }
                            }

                            if (y + row_span > rows)
                            {
                                if (x + 1 < columns)
                                {
                                    break;
                                }
                                else if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddRows)
                                {
                                    return(CalculateControlPositions(panel, columns, rows + 1));
                                }
                                else
                                {
                                    throw new ArgumentException();
                                }
                            }

                            grid[x, y] = c;

                            // Fill in the rest of this control's row/column extent with dummy
                            // controls, so that other controls don't get put there.
                            for (int i = 0; i < col_span; i++)
                            {
                                for (int j = 0; j < row_span; j++)
                                {
                                    if (i != 0 || j != 0)
                                    {
                                        grid[x + i, y + j] = dummy_control;
                                    }
                                }
                            }

                            // I know someone will kill me for using a goto, but
                            // sometimes they really are the easiest way...
                            goto Found;
                        }
                        else
                        {
                            // MS adds the controls only to the first row if
                            // GrowStyle is AddColumns and RowCount is 0,
                            // so interrupt the search for a free horizontal cell
                            // beyond the first one in the given vertical
                            if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddColumns &&
                                settings.RowCount == 0)
                            {
                                break;
                            }
                        }
                    }
                }

                // MS adds rows instead of columns even when GrowStyle is AddColumns,
                // but RowCount is 0.
                TableLayoutPanelGrowStyle adjustedGrowStyle = settings.GrowStyle;
                if (settings.GrowStyle == TableLayoutPanelGrowStyle.AddColumns)
                {
                    if (settings.RowCount == 0)
                    {
                        adjustedGrowStyle = TableLayoutPanelGrowStyle.AddRows;
                    }
                }

                switch (adjustedGrowStyle)
                {
                case TableLayoutPanelGrowStyle.AddColumns:
                    return(CalculateControlPositions(panel, columns + 1, rows));

                case TableLayoutPanelGrowStyle.AddRows:
                default:
                    return(CalculateControlPositions(panel, columns, rows + 1));

                case TableLayoutPanelGrowStyle.FixedSize:
                    throw new ArgumentException();
                }

                Found :;
            }

            return(grid);
        }