예제 #1
0
        public void RemoveTile(Tile tile)
        {
            if (!this.Controls.Contains(tile))
            {
                return;
            }

            PlaceholderTile placeholder           = new PlaceholderTile();
            TableLayoutPanelCellPosition position = this.GetCellPosition(tile);
            int colSpan = this.GetColumnSpan(tile);
            int rowSpan = this.GetRowSpan(tile);

            this.Controls.Remove(tile);
            this.Controls.Add(placeholder, position.Column, position.Row);
            this.SetColumnSpan(tile, colSpan);
            this.SetRowSpan(tile, rowSpan);
        }
예제 #2
0
        public void UseCustomLayout(int columns, int rows, int centerColumns = 0, int centerRows = 0)
        {
            if ((centerColumns == 0) && (centerRows == 0))
            {
                // Equal sized column and row layout.

                // Calculate counts and sizes.
                this.Puppet.ColumnCount = columns;
                this.Puppet.RowCount    = rows;
                float width  = 100.0f / columns;
                float height = 100.0f / rows;

                // Adjust columns.
                this.Puppet.ColumnStyles.Clear();
                for (int c = 0; c < columns; c++)
                {
                    this.Puppet.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, width));
                }

                // Adjust rows.
                this.Puppet.RowStyles.Clear();
                for (int r = 0; r < rows; r++)
                {
                    this.Puppet.RowStyles.Add(new RowStyle(SizeType.Percent, height));
                }
            }
            else
            {
                // Equal sized side columns or rows with larger center rows or columns.

                // Calculate counts and sizes.
                int sideColumns = columns;
                int sideRows    = rows;

                int   totalColumns    = sideColumns + centerColumns;
                int   totalRows       = sideRows + centerRows;
                float centerFactor    = 2.0f; // Multiple of the center tile size compared to side tiles.
                float sideColumnWidth = 100.0f / (sideColumns + centerColumns * centerFactor);
                float sideRowHeight   = 100.0f / (sideRows + centerRows * centerFactor);

                // Set Column and Row counts.
                this.Puppet.ColumnCount = totalColumns;
                this.Puppet.RowCount    = totalRows;

                // Clear styles.
                this.Puppet.ColumnStyles.Clear();
                this.Puppet.RowStyles.Clear();

                // Set style for columns.
                for (int c = 0; c < (int)Math.Ceiling(sideColumns / 2.0); c++)
                {
                    this.Puppet.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, sideColumnWidth));
                }
                for (int c = 0; c < centerColumns; c++)
                {
                    this.Puppet.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, sideColumnWidth * centerFactor));
                }
                for (int c = 0; c < (int)Math.Floor(sideColumns / 2.0); c++)
                {
                    this.Puppet.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, sideColumnWidth));
                }

                // Set style for the rows.
                for (int r = 0; r < (int)Math.Ceiling(sideRows / 2.0); r++)
                {
                    this.Puppet.RowStyles.Add(new RowStyle(SizeType.Percent, sideRowHeight));
                }
                for (int r = 0; r < centerRows; r++)
                {
                    this.Puppet.RowStyles.Add(new RowStyle(SizeType.Percent, sideRowHeight * centerFactor));
                }
                for (int r = 0; r < (int)Math.Floor(sideRows / 2.0); r++)
                {
                    this.Puppet.RowStyles.Add(new RowStyle(SizeType.Percent, sideRowHeight));
                }

                // Place spanning placeholders.
                PlaceholderTile placeholder;
                for (int c = 0; c < centerColumns; c++)
                {
                    placeholder = new PlaceholderTile();
                    this.Puppet.Controls.Add(placeholder, sideColumns + c - 1, 0);
                    this.Puppet.SetRowSpan(placeholder, sideRows);
                }
                for (int r = 0; r < centerRows; r++)
                {
                    placeholder = new PlaceholderTile();
                    this.Puppet.Controls.Add(placeholder, 0, sideRows + r - 1);
                    this.Puppet.SetColumnSpan(placeholder, sideColumns);
                }
            }

            this.Puppet.RefreshPlaceholders();
        }