Exemple #1
0
        public void SetRowSpan(object control, int value)
        {
            if (value < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidArgument, "RowSpan", (value).ToString(CultureInfo.CurrentCulture)));
            }
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            if (IsStub)
            {
                _stub.SetRowSpan(control, value);
            }
            else
            {
                IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
                // LayoutInfo.SetColumnSpan() throws ArgumentException if out of range.
                if (element.Container != null)
                {
                    TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
                }
                TableLayout.GetLayoutInfo(element).RowSpan = value;
                LayoutTransaction.DoLayout(element.Container, element, PropertyNames.RowSpan);
                Debug.Assert(GetRowSpan(element) == value, "row span should equal to the value we set");
            }
        }
Exemple #2
0
 private void SetCellPosition(object control, int row, int column, bool rowSpecified, bool colSpecified)
 {
     if (IsStub)
     {
         if (colSpecified)
         {
             _stub.SetColumn(control, column);
         }
         if (rowSpecified)
         {
             _stub.SetRow(control, row);
         }
     }
     else
     {
         IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
         if (element.Container != null)
         {
             TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
         }
         TableLayout.LayoutInfo layoutInfo = TableLayout.GetLayoutInfo(element);
         if (colSpecified)
         {
             layoutInfo.ColumnPosition = column;
         }
         if (rowSpecified)
         {
             layoutInfo.RowPosition = row;
         }
         LayoutTransaction.DoLayout(element.Container, element, PropertyNames.TableIndex);
         Debug.Assert(!colSpecified || GetColumn(element) == column, "column position shoule equal to what we set");
         Debug.Assert(!rowSpecified || GetRow(element) == row, "row position shoule equal to what we set");
     }
 }
        private void ScaleAbsoluteStyles(SizeF factor)
        {
            TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(this);
            int i = 0;

            // VSWhidbey 432427: the last row/column can be larger than the
            // absolutely styled column width.
            int lastRowHeight = -1;
            int lastRow       = containerInfo.Rows.Length - 1;

            if (containerInfo.Rows.Length > 0)
            {
                lastRowHeight = containerInfo.Rows[lastRow].MinSize;
            }

            int lastColumnHeight = -1;
            int lastColumn       = containerInfo.Columns.Length - 1;

            if (containerInfo.Columns.Length > 0)
            {
                lastColumnHeight = containerInfo.Columns[containerInfo.Columns.Length - 1].MinSize;
            }

            foreach (ColumnStyle cs in ColumnStyles)
            {
                if (cs.SizeType == SizeType.Absolute)
                {
                    if (i == lastColumn && lastColumnHeight > 0)
                    {
                        // the last column is typically expanded to fill the table. use the actual
                        // width in this case.
                        cs.Width = (float)Math.Round(lastColumnHeight * factor.Width);
                    }
                    else
                    {
                        cs.Width = (float)Math.Round(cs.Width * factor.Width);
                    }
                }
                i++;
            }

            i = 0;

            foreach (RowStyle rs in RowStyles)
            {
                if (rs.SizeType == SizeType.Absolute)
                {
                    if (i == lastRow && lastRowHeight > 0)
                    {
                        // the last row is typically expanded to fill the table. use the actual
                        // width in this case.
                        rs.Height = (float)Math.Round(lastRowHeight * factor.Height);
                    }
                    else
                    {
                        rs.Height = (float)Math.Round(rs.Height * factor.Height);
                    }
                }
            }
        }
Exemple #4
0
        public void SetRowSpan(object control, int value)
        {
            ArgumentNullException.ThrowIfNull(control);

            if (value < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(value), value));
            }

            if (IsStub)
            {
                _stub.SetRowSpan(control, value);
            }
            else
            {
                IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
                if (element.Container is not null)
                {
                    TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
                }

                TableLayout.GetLayoutInfo(element).RowSpan = value;
                LayoutTransaction.DoLayout(element.Container, element, PropertyNames.RowSpan);
                Debug.Assert(GetRowSpan(element) == value, "row span should equal to the value we set");
            }
        }
Exemple #5
0
            /// <devdoc> ApplySettings - applies settings from the stub into a full-fledged
            ///          TableLayoutSettings.
            ///
            ///          NOTE: this is a one-time only operation - there is data loss to the stub
            ///          as a result of calling this function. we hand as much over to the other guy
            ///          so we dont have to reallocate anything
            /// </devdoc>
            internal void ApplySettings(TableLayoutSettings settings)
            {
                //
                // apply row,column,rowspan,colspan
                //
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control appliedControl = containerInfo.Container as Control;

                if (appliedControl != null && controlsInfo != null)
                {
                    // we store the control names, look up the controls
                    // in the appliedControl's control collection and apply the row,column settings.
                    foreach (object controlName in controlsInfo.Keys)
                    {
                        ControlInformation controlInfo = controlsInfo[controlName];

                        // Look for the control in our table, we have to go through
                        // PropertyDescriptor rather than just going using appliedControl.Controls[controlName]
                        // because the Name property is shadowed at design time
                        foreach (Control tableControl in appliedControl.Controls)
                        {
                            if (tableControl != null)
                            {
                                string             name = null;
                                PropertyDescriptor prop = TypeDescriptor.GetProperties(tableControl)["Name"];
                                if (prop != null && prop.PropertyType == typeof(string))
                                {
                                    name = prop.GetValue(tableControl) as string;
                                }
                                else
                                {
                                    Debug.Fail("Name property missing on control");
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(name, controlName as string, /* ignoreCase = */ false))
                                {
                                    settings.SetRow(tableControl, controlInfo.Row);
                                    settings.SetColumn(tableControl, controlInfo.Column);
                                    settings.SetRowSpan(tableControl, controlInfo.RowSpan);
                                    settings.SetColumnSpan(tableControl, controlInfo.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }

                //
                // assign over the row and column styles
                //
                containerInfo.RowStyles    = rowStyles;
                containerInfo.ColumnStyles = columnStyles;

                // since we've given over the styles to the other guy, null out.
                columnStyles = null;
                rowStyles    = null;

                // set a flag for assertion detection.
                isValid = false;
            }
 public int[] GetRowHeights()
 {
     TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(this);
     if (containerInfo.Rows == null)
     {
         return(new int[0]);
     }
     int[] numArray = new int[containerInfo.Rows.Length];
     for (int i = 0; i < containerInfo.Rows.Length; i++)
     {
         numArray[i] = containerInfo.Rows[i].MinSize;
     }
     return(numArray);
 }
        private void ScaleAbsoluteStyles(SizeF factor)
        {
            TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(this);
            int num     = 0;
            int minSize = -1;
            int index   = containerInfo.Rows.Length - 1;

            if (containerInfo.Rows.Length > 0)
            {
                minSize = containerInfo.Rows[index].MinSize;
            }
            int num4 = -1;
            int num5 = containerInfo.Columns.Length - 1;

            if (containerInfo.Columns.Length > 0)
            {
                num4 = containerInfo.Columns[containerInfo.Columns.Length - 1].MinSize;
            }
            foreach (ColumnStyle style in (IEnumerable)this.ColumnStyles)
            {
                if (style.SizeType == SizeType.Absolute)
                {
                    if ((num == num5) && (num4 > 0))
                    {
                        style.Width = (float)Math.Round((double)(num4 * factor.Width));
                    }
                    else
                    {
                        style.Width = (float)Math.Round((double)(style.Width * factor.Width));
                    }
                }
                num++;
            }
            num = 0;
            foreach (RowStyle style2 in (IEnumerable)this.RowStyles)
            {
                if (style2.SizeType == SizeType.Absolute)
                {
                    if ((num == index) && (minSize > 0))
                    {
                        style2.Height = (float)Math.Round((double)(minSize * factor.Height));
                    }
                    else
                    {
                        style2.Height = (float)Math.Round((double)(style2.Height * factor.Height));
                    }
                }
            }
        }
Exemple #8
0
        public int[] GetColumnWidths()
        {
            TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(this);
            if (containerInfo.Columns == null)
            {
                return(new int[0]);
            }

            int[] cw = new int[containerInfo.Columns.Length];
            for (int i = 0; i < containerInfo.Columns.Length; i++)
            {
                cw[i] = containerInfo.Columns[i].MinSize;
            }
            return(cw);
        }
Exemple #9
0
        public int[] GetRowHeights()
        {
            TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(this);
            if (containerInfo.Rows == null)
            {
                return(Array.Empty <int>());
            }

            int[] rh = new int[containerInfo.Rows.Length];
            for (int i = 0; i < containerInfo.Rows.Length; i++)
            {
                rh[i] = containerInfo.Rows[i].MinSize;
            }
            return(rh);
        }
Exemple #10
0
            internal void ApplySettings(TableLayoutSettings settings)
            {
                TableLayout.ContainerInfo containerInfo = TableLayout.GetContainerInfo(settings.Owner);
                Control container = containerInfo.Container as Control;

                if ((container != null) && (this.controlsInfo != null))
                {
                    foreach (object obj2 in this.controlsInfo.Keys)
                    {
                        TableLayoutSettings.ControlInformation information = this.controlsInfo[obj2];
                        foreach (Control control2 in container.Controls)
                        {
                            if (control2 != null)
                            {
                                string             str        = null;
                                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(control2)["Name"];
                                if ((descriptor != null) && (descriptor.PropertyType == typeof(string)))
                                {
                                    str = descriptor.GetValue(control2) as string;
                                }
                                if (WindowsFormsUtils.SafeCompareStrings(str, obj2 as string, false))
                                {
                                    settings.SetRow(control2, information.Row);
                                    settings.SetColumn(control2, information.Column);
                                    settings.SetRowSpan(control2, information.RowSpan);
                                    settings.SetColumnSpan(control2, information.ColumnSpan);
                                    break;
                                }
                            }
                        }
                    }
                }
                containerInfo.RowStyles    = this.rowStyles;
                containerInfo.ColumnStyles = this.columnStyles;
                this.columnStyles          = null;
                this.rowStyles             = null;
                this.isValid = false;
            }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            int cellBorderWidth = this.CellBorderWidth;

            TableLayout.ContainerInfo       containerInfo   = TableLayout.GetContainerInfo(this);
            TableLayout.Strip[]             columns         = containerInfo.Columns;
            TableLayout.Strip[]             rows            = containerInfo.Rows;
            TableLayoutPanelCellBorderStyle cellBorderStyle = this.CellBorderStyle;

            if ((columns != null) && (rows != null))
            {
                int       num6;
                int       length           = columns.Length;
                int       num3             = rows.Length;
                int       num4             = 0;
                int       num5             = 0;
                Graphics  g                = e.Graphics;
                Rectangle displayRectangle = this.DisplayRectangle;
                Rectangle clipRectangle    = e.ClipRectangle;
                bool      flag             = this.RightToLeft == RightToLeft.Yes;
                if (flag)
                {
                    num6 = displayRectangle.Right - (cellBorderWidth / 2);
                }
                else
                {
                    num6 = displayRectangle.X + (cellBorderWidth / 2);
                }
                for (int i = 0; i < length; i++)
                {
                    int y = displayRectangle.Y + (cellBorderWidth / 2);
                    if (flag)
                    {
                        num6 -= columns[i].MinSize;
                    }
                    for (int j = 0; j < num3; j++)
                    {
                        Rectangle bound = new Rectangle(num6, y, columns[i].MinSize, rows[j].MinSize);
                        Rectangle rect  = new Rectangle(bound.X + ((cellBorderWidth + 1) / 2), bound.Y + ((cellBorderWidth + 1) / 2), bound.Width - ((cellBorderWidth + 1) / 2), bound.Height - ((cellBorderWidth + 1) / 2));
                        if (clipRectangle.IntersectsWith(rect))
                        {
                            using (TableLayoutCellPaintEventArgs args = new TableLayoutCellPaintEventArgs(g, clipRectangle, rect, i, j))
                            {
                                this.OnCellPaint(args);
                            }
                            ControlPaint.PaintTableCellBorder(cellBorderStyle, g, bound);
                        }
                        y += rows[j].MinSize;
                        if (i == 0)
                        {
                            num5 += rows[j].MinSize;
                        }
                    }
                    if (!flag)
                    {
                        num6 += columns[i].MinSize;
                    }
                    num4 += columns[i].MinSize;
                }
                if ((base.HScroll || base.VScroll) || (cellBorderStyle == TableLayoutPanelCellBorderStyle.None))
                {
                    ControlPaint.PaintTableControlBorder(cellBorderStyle, g, displayRectangle);
                }
                else
                {
                    Rectangle rectangle5 = new Rectangle((cellBorderWidth / 2) + displayRectangle.X, (cellBorderWidth / 2) + displayRectangle.Y, displayRectangle.Width - cellBorderWidth, displayRectangle.Height - cellBorderWidth);
                    switch (cellBorderStyle)
                    {
                    case TableLayoutPanelCellBorderStyle.Inset:
                        g.DrawLine(SystemPens.ControlDark, rectangle5.Right, rectangle5.Y, rectangle5.Right, rectangle5.Bottom);
                        g.DrawLine(SystemPens.ControlDark, rectangle5.X, (rectangle5.Y + rectangle5.Height) - 1, (rectangle5.X + rectangle5.Width) - 1, (rectangle5.Y + rectangle5.Height) - 1);
                        break;

                    case TableLayoutPanelCellBorderStyle.Outset:
                    {
                        using (Pen pen = new Pen(SystemColors.Window))
                        {
                            g.DrawLine(pen, (rectangle5.X + rectangle5.Width) - 1, rectangle5.Y, (rectangle5.X + rectangle5.Width) - 1, (rectangle5.Y + rectangle5.Height) - 1);
                            g.DrawLine(pen, rectangle5.X, (rectangle5.Y + rectangle5.Height) - 1, (rectangle5.X + rectangle5.Width) - 1, (rectangle5.Y + rectangle5.Height) - 1);
                            break;
                        }
                    }

                    default:
                        ControlPaint.PaintTableCellBorder(cellBorderStyle, g, rectangle5);
                        break;
                    }
                    ControlPaint.PaintTableControlBorder(cellBorderStyle, g, displayRectangle);
                }
            }
        }
        /// <include file='doc\TableLayoutPanel.uex' path='docs/doc[@for="TableLayoutPanel.OnPaint"]/*' />
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);



            // paint borderstyles on top of the background image in WM_ERASEBKGND

            int cellBorderWidth = this.CellBorderWidth;

            TableLayout.ContainerInfo       containerInfo   = TableLayout.GetContainerInfo(this);
            TableLayout.Strip[]             colStrips       = containerInfo.Columns;
            TableLayout.Strip[]             rowStrips       = containerInfo.Rows;
            TableLayoutPanelCellBorderStyle cellBorderStyle = this.CellBorderStyle;



            if (colStrips == null || rowStrips == null)
            {
                return;
            }
            int cols = colStrips.Length;
            int rows = rowStrips.Length;

            int totalColumnWidths = 0, totalColumnHeights = 0;

            Graphics  g           = e.Graphics;
            Rectangle displayRect = DisplayRectangle;
            Rectangle clipRect    = e.ClipRectangle;

            //leave the space for the border
            int  startx;
            bool isRTL = (RightToLeft == RightToLeft.Yes);

            if (isRTL)
            {
                startx = displayRect.Right - (cellBorderWidth / 2);
            }
            else
            {
                startx = displayRect.X + (cellBorderWidth / 2);
            }

            for (int i = 0; i < cols; i++)
            {
                int starty = displayRect.Y + (cellBorderWidth / 2);

                if (isRTL)
                {
                    startx -= colStrips[i].MinSize;
                }

                for (int j = 0; j < rows; j++)
                {
                    Rectangle outsideCellBounds = new Rectangle(startx, starty, ((TableLayout.Strip)colStrips[i]).MinSize, ((TableLayout.Strip)rowStrips[j]).MinSize);

                    Rectangle insideCellBounds = new Rectangle(outsideCellBounds.X + (cellBorderWidth + 1) / 2, outsideCellBounds.Y + (cellBorderWidth + 1) / 2, outsideCellBounds.Width - (cellBorderWidth + 1) / 2, outsideCellBounds.Height - (cellBorderWidth + 1) / 2);

                    if (clipRect.IntersectsWith(insideCellBounds))
                    {
                        //first, call user's painting code
                        using (TableLayoutCellPaintEventArgs pcea = new TableLayoutCellPaintEventArgs(g, clipRect, insideCellBounds, i, j)) {
                            OnCellPaint(pcea);
                        }
                        // paint the table border on top.
                        ControlPaint.PaintTableCellBorder(cellBorderStyle, g, outsideCellBounds);
                    }
                    starty += rowStrips[j].MinSize;
                    // Only sum this up once...
                    if (i == 0)
                    {
                        totalColumnHeights += rowStrips[j].MinSize;
                    }
                }

                if (!isRTL)
                {
                    startx += colStrips[i].MinSize;
                }
                totalColumnWidths += colStrips[i].MinSize;
            }


            if (!HScroll && !VScroll && cellBorderStyle != TableLayoutPanelCellBorderStyle.None)
            {
                Rectangle tableBounds = new Rectangle(cellBorderWidth / 2 + displayRect.X, cellBorderWidth / 2 + displayRect.Y, displayRect.Width - cellBorderWidth, displayRect.Height - cellBorderWidth);
                // paint the border of the table if we are not auto scrolling.
                // if the borderStyle is Inset or Outset, we can only paint the lower bottom half since otherwise we will have 1 pixel loss at the border.
                if (cellBorderStyle == TableLayoutPanelCellBorderStyle.Inset)
                {
                    g.DrawLine(SystemPens.ControlDark, tableBounds.Right, tableBounds.Y, tableBounds.Right, tableBounds.Bottom);
                    g.DrawLine(SystemPens.ControlDark, tableBounds.X, tableBounds.Y + tableBounds.Height - 1, tableBounds.X + tableBounds.Width - 1, tableBounds.Y + tableBounds.Height - 1);
                }
                else if (cellBorderStyle == TableLayoutPanelCellBorderStyle.Outset)
                {
                    using (Pen pen = new Pen(SystemColors.Window)) {
                        g.DrawLine(pen, tableBounds.X + tableBounds.Width - 1, tableBounds.Y, tableBounds.X + tableBounds.Width - 1, tableBounds.Y + tableBounds.Height - 1);
                        g.DrawLine(pen, tableBounds.X, tableBounds.Y + tableBounds.Height - 1, tableBounds.X + tableBounds.Width - 1, tableBounds.Y + tableBounds.Height - 1);
                    }
                }
                else
                {
                    ControlPaint.PaintTableCellBorder(cellBorderStyle, g, tableBounds);
                }
                ControlPaint.PaintTableControlBorder(cellBorderStyle, g, displayRect);
            }
            else
            {
                ControlPaint.PaintTableControlBorder(cellBorderStyle, g, displayRect);
            }
        }