解决方法
是的你可以.
使用TableLayoutPanel的CellPaint事件来测试哪个行/列已经调用了事件,然后使用Graphic对象的大小来设置矩形的颜色.
像这样(对于第一行和第三行):
private void Form_Load(object sender,EventArgs e) { this.tableLayoutPanel1.CellPaint += new TableLayoutCellPaintEventHandler(tableLayoutPanel1_CellPaint); } void tableLayoutPanel1_CellPaint(object sender,TableLayoutCellPaintEventArgs e) { if (e.Row == 0 || e.Row == 2) { Graphics g = e.Graphics; Rectangle r = e.CellBounds; g.FillRectangle(Brushes.Blue,r); } }