I have TableLayoutPanel
placed on windows form. It has 3 columns and 2 rows. I have set CellBorderStyle property of TableLayoutPanel to "Single". I want to hide second column dynamically. To achieving this I have write following code:
tableLayoutPanel1.ColumnStyles[0].Width = 0;
But then TableLayoutPanel
will look like below.See the border, border becomes thick: Can anyone resolve this issue?
You will need to owner.draw the TLP:
This is a way: Turn off the CellBorder
and code this event
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);
}
}
But you should rather ask yourself why the situation has arisen and if the user shouldn't maybe actually see the there is a column hidden..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.