【问题标题】:TableLayoutPanel cell border issueTableLayoutPanel 单元格边框问题
【发布时间】:2016-10-05 04:40:26
【问题描述】:

我已将TableLayoutPanel 放置在 Windows 窗体上。 它有 3 列和 2 行。 我已将 TableLayoutPanel 的 CellBorderStyle 属性设置为“Single”。 我想动态隐藏第二列。 为此,我编写了以下代码:

tableLayoutPanel1.ColumnStyles[0].Width = 0;

但是TableLayoutPanel 会如下所示。看到边框,边框变粗了: 谁能解决这个问题?

【问题讨论】:

    标签: c# .net tablelayoutpanel


    【解决方案1】:

    您需要 owner.draw 绘制 TLP:

    隐藏第 3 列:

    这是一种方法:关闭CellBorder 并编码此事件

    private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
    {
        Rectangle r = e.CellBounds;
        using (Pen pen = new Pen(Color.DarkGoldenrod))
        {
            // top and left lines
            e.Graphics.DrawLine(pen, r.X, r.Y, r.X + r.Width, r.Y);
            e.Graphics.DrawLine(pen, r.X, r.Y, r.X, r.Y + r.Height);
            // last row? move hor.lines 1 up!
            int cy = e.Row == tableLayoutPanel1.RowCount - 1 ? -1 : 0;
            if (cy != 0) e.Graphics.DrawLine(pen, r.X, r.Y + r.Height + cy, 
                                    r.X + r.Width, r.Y + r.Height + cy);
            // last column ? move vert. lines 1 left!
            int cx = e.Column == tableLayoutPanel1.ColumnCount - 1 ? -1 : 0;
            if (cx != 0) e.Graphics.DrawLine(pen, r.X + r.Width + cx, r.Y, 
                                    r.X + r.Width + cx, r.Y + r.Height);
        }
    }
    

    但是你应该问问自己为什么会出现这种情况,如果用户不应该真正看到隐藏的一列..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多