You could use CellPaint
event and draw the border rectangle when needed:
tableLayoutPanel1.CellPaint += tableLayoutPanel1_CellPaint;
The handler:
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (e.Column == 1 && e.Row == 0)
e.Graphics.DrawRectangle(new Pen(Color.Blue), e.CellBounds);
}
You can draw any kind of border using ControlPaint
:
if (e.Column == 1 && e.Row == 0)
{
var rectangle = e.CellBounds;
rectangle.Inflate(-1, -1);
ControlPaint.DrawBorder3D(e.Graphics, rectangle, Border3DStyle.Raised, Border3DSide.All); // 3D border
ControlPaint.DrawBorder(e.Graphics, rectangle, Color.Red, ButtonBorderStyle.Dotted); // dotted border
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…