Can i add particular color for entire Row or Column in TableLayoutPanel ? How ? please provide sample code if any ..
Thanks in adv.
I found this answer much easier to implement:
This allowed me to put a full backcolor on my cell.
Panel
, which has a backcolor, and Dock
that Panel
in my TableLayoutPanel
Then that TableLayoutPanel
Cell has a
backcolor.
My Code ended up looking like this:
Panel backgroundColorPanel = new Panel();
backgroundColorPanel.BackColor = Color.FromArgb(243, 243, 243);
backgroundColorPanel.Dock = DockStyle.Fill;
backgroundColorPanel.Margin = new Padding(0);
backgroundColorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left));
backgroundColorPanel.AutoSize = true;
backgroundColorPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.originalTableLayoutPanel.Controls.Add(backgroundColorPanel, 0, row);
http://www.codeguru.com/forum/showthread.php?t=444944
Yes you can.
Use the TableLayoutPanel's CellPaint event to test for which row/column has called the event and then use a Graphic object size to the rectangle to set the cell's color.
Like this (for the first and third rows):
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);
}
}