'C# Change background color of a table cell inTableLayoutPanel
I am trying to change the background color of a table cell inside a TableLayoutPanel programmatically. The cells can either be null or taken by a user control during runtime (always changing).
I was doing this:
TableName.GetControlFromPosition(column, row).BackColor = Color.CornflowerBlue;
Of course, this only works if there is something at that cell. How can I also change the properties of a null cell at runtime?
Solution 1:[1]
when the cell is null, you can not set it's BackColor property. When set color, you should check if it is null. And you can set color of controls in the cells rather than cell's BackColor. example
Solution 2:[2]
You can use TableLayoutPanel tlp = new TableLayoutPanel(); tlp.BackColor = Color.FromArgb(150,0,0,0);
That should do the trickā¦.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gry |
| Solution 2 | Jules |
