Draw borders around some cells in a tablelayoutpanel
Access properties for the tableLayoutPanel and Set the CellBorderStyle to Single
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
}