2016-10-04 8 views
0

私はTableLayoutPanelをWindowsフォームに配置しています。 3列2行です。 TableLayoutPanelのCellBorderStyleプロパティを "Single"に設定しました。 2番目の列を動的に非表示にしたい。 これを達成するために、私は次のコードの書き込みがあります。TableLayoutPanelセル境界の問題

tableLayoutPanel1.ColumnStyles[0].Width = 0; 

しかし、その後TableLayoutPanelがbelow.Seeのように境界線を見ていきますが、境界線が太くなる: enter image description here 誰もがこの問題を解決することはできますか?

答えて

2

あなたはTLPをowner.drawする必要があります。これは、方法ですenter image description here

:3列を非表示

このイベントは

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); 
    } 
} 

​​とコードをオフにします。しかし、あなたなぜ状況が発生したのか、実際に隠れている列がユーザーに表示されないようにするべきかどうかを自問してください。

関連する問題