簡體   English   中英

TableLayoutPanel單元格邊框問題

[英]TableLayoutPanel cell border issue

我將TableLayoutPanel放在Windows窗體上。 它具有3列和2行。 我已經將TableLayoutPanel的CellBorderStyle屬性設置為“ Single”。 我想動態隱藏第二列。 為此,我編寫了以下代碼:

tableLayoutPanel1.ColumnStyles[0].Width = 0;

但是隨后TableLayoutPanel將如下所示。看到邊框,邊框變粗了: 在此處輸入圖片說明 誰能解決這個問題?

您將需要owner.draw TLP:

隱藏第三欄: 在此處輸入圖片說明

這是一種方法:關閉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);
    }
}

但是您應該問自己,為什么會出現這種情況,以及用戶是否可能實際上看不到隱藏的列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM