public TableLayoutPanel() { settings = new TableLayoutSettings(this); cell_border_style = TableLayoutPanelCellBorderStyle.None; column_widths = new int[0]; row_heights = new int[0]; }
public TableLayoutPanel () { settings = new TableLayoutSettings(this); cell_border_style = TableLayoutPanelCellBorderStyle.None; column_widths = new int[0]; row_heights = new int[0]; }
public void TableLayoutPanel_CellBorderStyle_Set_GetReturnsExpected(TableLayoutPanelCellBorderStyle value) { var panel = new TableLayoutPanel { CellBorderStyle = value }; Assert.Equal(value, panel.CellBorderStyle); }
internal static int GetCellBorderWidth(TableLayoutPanelCellBorderStyle style) { switch (style) { case TableLayoutPanelCellBorderStyle.Single: return(1); case TableLayoutPanelCellBorderStyle.Inset: case TableLayoutPanelCellBorderStyle.Outset: return(2); case TableLayoutPanelCellBorderStyle.InsetDouble: case TableLayoutPanelCellBorderStyle.OutsetPartial: case TableLayoutPanelCellBorderStyle.OutsetDouble: return(3); } return(0); }
internal static void PaintTableControlBorder(TableLayoutPanelCellBorderStyle borderStyle, Graphics g, Rectangle bound) { int x = bound.X; int y = bound.Y; int right = bound.Right; int bottom = bound.Bottom; switch (borderStyle) { case TableLayoutPanelCellBorderStyle.None: case TableLayoutPanelCellBorderStyle.Single: break; case TableLayoutPanelCellBorderStyle.Inset: case TableLayoutPanelCellBorderStyle.InsetDouble: { g.DrawLine(SystemPens.ControlDark, x, y, right - 1, y); g.DrawLine(SystemPens.ControlDark, x, y, x, bottom - 1); using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, right - 1, y, right - 1, bottom - 1); g.DrawLine(pen, x, bottom - 1, right - 1, bottom - 1); break; } } case TableLayoutPanelCellBorderStyle.Outset: case TableLayoutPanelCellBorderStyle.OutsetDouble: case TableLayoutPanelCellBorderStyle.OutsetPartial: using (Pen pen2 = new Pen(SystemColors.Window)) { g.DrawLine(pen2, x, y, right - 1, y); g.DrawLine(pen2, x, y, x, bottom - 1); } g.DrawLine(SystemPens.ControlDark, right - 1, y, right - 1, bottom - 1); g.DrawLine(SystemPens.ControlDark, x, bottom - 1, right - 1, bottom - 1); break; default: return; } }
internal static void PaintTableCellBorder(TableLayoutPanelCellBorderStyle borderStyle, Graphics g, Rectangle bound) { switch (borderStyle) { case TableLayoutPanelCellBorderStyle.None: break; case TableLayoutPanelCellBorderStyle.Single: g.DrawRectangle(SystemPens.ControlDark, bound); return; case TableLayoutPanelCellBorderStyle.Inset: using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, bound.X, bound.Y, (bound.X + bound.Width) - 1, bound.Y); g.DrawLine(pen, bound.X, bound.Y, bound.X, (bound.Y + bound.Height) - 1); } g.DrawLine(SystemPens.ControlDark, (bound.X + bound.Width) - 1, bound.Y, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); g.DrawLine(SystemPens.ControlDark, bound.X, (bound.Y + bound.Height) - 1, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); return; case TableLayoutPanelCellBorderStyle.InsetDouble: g.DrawRectangle(SystemPens.Control, bound); bound = new Rectangle(bound.X + 1, bound.Y + 1, bound.Width - 1, bound.Height - 1); using (Pen pen2 = new Pen(SystemColors.Window)) { g.DrawLine(pen2, bound.X, bound.Y, (bound.X + bound.Width) - 1, bound.Y); g.DrawLine(pen2, bound.X, bound.Y, bound.X, (bound.Y + bound.Height) - 1); } g.DrawLine(SystemPens.ControlDark, (bound.X + bound.Width) - 1, bound.Y, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); g.DrawLine(SystemPens.ControlDark, bound.X, (bound.Y + bound.Height) - 1, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); return; case TableLayoutPanelCellBorderStyle.Outset: { g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, (bound.X + bound.Width) - 1, bound.Y); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X, (bound.Y + bound.Height) - 1); using (Pen pen3 = new Pen(SystemColors.Window)) { g.DrawLine(pen3, (bound.X + bound.Width) - 1, bound.Y, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); g.DrawLine(pen3, bound.X, (bound.Y + bound.Height) - 1, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); break; } } case TableLayoutPanelCellBorderStyle.OutsetDouble: case TableLayoutPanelCellBorderStyle.OutsetPartial: g.DrawRectangle(SystemPens.Control, bound); bound = new Rectangle(bound.X + 1, bound.Y + 1, bound.Width - 1, bound.Height - 1); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, (bound.X + bound.Width) - 1, bound.Y); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X, (bound.Y + bound.Height) - 1); using (Pen pen4 = new Pen(SystemColors.Window)) { g.DrawLine(pen4, (bound.X + bound.Width) - 1, bound.Y, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); g.DrawLine(pen4, bound.X, (bound.Y + bound.Height) - 1, (bound.X + bound.Width) - 1, (bound.Y + bound.Height) - 1); } break; default: return; } }
public void TableLayoutPanel_CellBorderStyle_SetInvalid_ThrowsArgumentOutOfRangeException(TableLayoutPanelCellBorderStyle value) { var panel = new TableLayoutPanel(); Assert.Throws <ArgumentOutOfRangeException>("value", () => panel.CellBorderStyle = value); }
internal static int GetCellBorderWidth (TableLayoutPanelCellBorderStyle style) { switch (style) { case TableLayoutPanelCellBorderStyle.Single: return 1; case TableLayoutPanelCellBorderStyle.Inset: case TableLayoutPanelCellBorderStyle.Outset: return 2; case TableLayoutPanelCellBorderStyle.InsetDouble: case TableLayoutPanelCellBorderStyle.OutsetPartial: case TableLayoutPanelCellBorderStyle.OutsetDouble: return 3; } return 0; }
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); } }
//paint individual cell of the table internal static void PaintTableCellBorder(TableLayoutPanelCellBorderStyle borderStyle, Graphics g, Rectangle bound) { //next, paint the cell border switch (borderStyle) { case TableLayoutPanelCellBorderStyle.None : break; case TableLayoutPanelCellBorderStyle.Single : g.DrawRectangle(SystemPens.ControlDark, bound); break; case TableLayoutPanelCellBorderStyle.Inset : using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, bound.X, bound.Y, bound.X + bound.Width - 1, bound.Y); g.DrawLine(pen, bound.X, bound.Y, bound.X, bound.Y + bound.Height - 1); } g.DrawLine(SystemPens.ControlDark, bound.X + bound.Width - 1, bound.Y, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); break; case TableLayoutPanelCellBorderStyle.InsetDouble : g.DrawRectangle(SystemPens.Control, bound); //draw the shadow bound = new Rectangle(bound.X + 1, bound.Y + 1, bound.Width - 1, bound.Height - 1); using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, bound.X, bound.Y, bound.X + bound.Width - 1, bound.Y); g.DrawLine(pen, bound.X, bound.Y, bound.X, bound.Y + bound.Height - 1); } g.DrawLine(SystemPens.ControlDark, bound.X + bound.Width - 1, bound.Y, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); break; case TableLayoutPanelCellBorderStyle.Outset : g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X + bound.Width - 1, bound.Y); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X, bound.Y + bound.Height - 1); using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, bound.X + bound.Width - 1, bound.Y, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); g.DrawLine(pen, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); } break; case TableLayoutPanelCellBorderStyle.OutsetDouble : case TableLayoutPanelCellBorderStyle.OutsetPartial : g.DrawRectangle(SystemPens.Control, bound); //draw the shadow bound = new Rectangle(bound.X + 1, bound.Y + 1, bound.Width - 1, bound.Height - 1); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X + bound.Width - 1, bound.Y); g.DrawLine(SystemPens.ControlDark, bound.X, bound.Y, bound.X, bound.Y + bound.Height - 1); using (Pen pen = new Pen(SystemColors.Window)) { g.DrawLine(pen, bound.X + bound.Width - 1, bound.Y, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); g.DrawLine(pen, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width - 1, bound.Y + bound.Height - 1); } break; } }
protected bool SetStyle(string tag, UIType type, SizeType row0SizeType, int row0Hight, SizeType column0SizeType, int column0Width, TableLayoutPanelCellBorderStyle tlpcs) { bool b = default(bool); try { this.pTag = tag; this.pType = type; this.tlp.RowStyles[0] = new RowStyle(row0SizeType, row0Hight); this.tlp.ColumnStyles[0] = new ColumnStyle(column0SizeType, column0Width); this.tlp.CellBorderStyle = tlpcs; b = true; } catch (Exception) { b = false; } return(b); }