Hi, I have a TableLayoutPanel and every time I put a label into one of the cells, it snaps to the top left corner. How can I get to it not do this or change where it snaps.
Also, is it possible to change a specific cell's background color?
Thanks!
Hi, I have a TableLayoutPanel and every time I put a label into one of the cells, it snaps to the top left corner. How can I get to it not do this or change where it snaps.
Also, is it possible to change a specific cell's background color?
Thanks!
Soo, you can control where a label 'snaps' in a cell by setting the Dock property on the label. It will dock within the confines of the cell. I don't believe you can change the background color of a cell. One way to work around this is to put a panel in each cell, set it to dock using the full cell, and set the back ground color of the panel.
To change the location of a control in a cell use the control's Anchor property.
To change the background color of a cell within a TableLayoutPanel, use the control's CellPaint event to test which Column and/or Row is being painted and set the color accordingly.
The following will set the background color of the cell at 1, 1 to red:
private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e) {
if (e.Column == 1 && e.Row == 1) {
e.Graphics.FillRectangle(Brushes.Red, e.CellBounds);
}
}