当tableLayoutPanel列单元格或行单元格合并后中间的线条如何才能去除掉了
急 在线等!!!

解决方案 »

  1.   

    可能你要把边框去掉
    tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;(如果一定要边框)然后在相应CellPaint中自己画合并后的边框,可以充分用参数中的Row,Column以及CellBounds信息。
      

  2.   

    如果您希望控件跨多个行或多个列,可设置控件上的   RowSpan   和   ColumnSpan   属性。有关更多信息,请参见演练:使用   TableLayoutPanel   在   Windows   窗体上排列控件。   
        
      若要在单元格中对齐控件,或在单元格内拉伸控件,请使用控件的   Anchor   属性。有关更多信息,请参见演练:使用   TableLayoutPanel   在   Windows   窗体上排列控件。   
        
      显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您现用的设置或版本。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见   Visual   Studio   设置。
      

  3.   

    还是苦力活 :)public class BorderedTableLayoutPanel : TableLayoutPanel
    {
        Pen borderPen;
        public Pen BorderPen { get { return this.borderPen; } set { this.borderPen = value; } }    protected override void OnCreateControl()
        {
            base.OnCreateControl();        this.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
            this.borderPen = this.borderPen == null ? Pens.DarkGray : this.borderPen;
            this.ControlAdded += delegate { this.cellBorders = null; };
            this.ControlRemoved += delegate { this.cellBorders = null; };
        }    protected override void OnCellPaint(TableLayoutCellPaintEventArgs e)
        {
            base.OnCellPaint(e);        Pen pen = this.BorderPen;
            Borders borders = this[e.Row, e.Column];
            Point topleft = new Point(e.CellBounds.Left, e.CellBounds.Top);
            Point topright = new Point(e.CellBounds.Right - 1, e.CellBounds.Top);
            Point bottomleft = new Point(e.CellBounds.Left, e.CellBounds.Bottom - 1);
            Point bottomright = new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);        if ((borders & Borders.Left) == Borders.Left) e.Graphics.DrawLine(pen, topleft, bottomleft);
            if ((borders & Borders.Right) == Borders.Right) e.Graphics.DrawLine(pen, topright, bottomright);
            if ((borders & Borders.Top) == Borders.Top) e.Graphics.DrawLine(pen, topleft, topright);
            if ((borders & Borders.Bottom) == Borders.Bottom) e.Graphics.DrawLine(pen, bottomleft, bottomright);
        }    [Flags]
        enum Borders
        {
            None = 0, Left = 1, Right = 2, Top = 4, Bottom = 8,
        }    Borders[,] cellBorders;
        Borders this[int row, int col]
        {
            get 
            {
                if (this.cellBorders == null)
                {
                    PrepareCellBorders();
                }
                if (row < this.cellBorders.GetLength(0) && col < this.cellBorders.GetLength(1))
                {
                    return this.cellBorders[row, col];
                }
                return Borders.None;
            }
            set 
            {
                if (this.cellBorders == null)
                {
                    PrepareCellBorders();
                }
                if (row < this.cellBorders.GetLength(0) && col < this.cellBorders.GetLength(1))
                {
                    this.cellBorders[row, col] = value;
                }
            }
        }    private void PrepareCellBorders()
        {
            this.cellBorders = new Borders[this.RowCount, this.ColumnCount];
            for (int y = 0; y < cellBorders.GetLength(0); y++)
            {
                for (int x = 0; x < cellBorders.GetLength(1); x++)
                {
                    cellBorders[y, x] = Borders.Top | Borders.Left;
                    if (y == cellBorders.GetLength(0) - 1) cellBorders[y, x] |= Borders.Bottom;
                    if (x == cellBorders.GetLength(1) - 1) cellBorders[y, x] |= Borders.Right;
                }
            }        foreach (Control c in this.Controls)
            {
                int rowspan = this.GetRowSpan(c);
                int colspan = this.GetColumnSpan(c);
                TableLayoutPanelCellPosition pos = this.GetCellPosition(c);            for (int y = 0; y < rowspan; y++)
                {
                    for (int x = 0; x < colspan; x++)
                    {
                        if (y > 0) this[pos.Row + y, pos.Column + x] &= ~Borders.Top;
                        if (x > 0) this[pos.Row + y, pos.Column + x] &= ~Borders.Left;
                    }
                }
            }
        }}