Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am dynamically adding labels to cells in a table layout panel. Only the outlines of the labels are showing (not their text or background color).

Here is the heart of the routine that formats the table layout panel and adds the labels:

tlp.Controls.Clear();
tlp.SuspendLayout();
.
.
.
int[] columnWidths = GetWidthOfColumns(tlp, nList, maxColWidth);
FormatColNRow(tlp, nList[0].Height, maxRow, columnWidths);
PutNodesInGrid(tlp, nList, columnWidths);
.
.
.
tlp.ResumeLayout();
tlp.Refresh();
tlp.Focus();

Here are the lines of code from the method that actually adds the labels to the table layout panel:

tlp.Controls.Add(n);
tlp.SetCellPosition(n, new TableLayoutPanelCellPosition(n.ContainerColumn, n.ContainerRow));


The table layout panel is in the form (not in any other container). The labels are showing in the correct cell and with the correct size, but the text and background color of each label is not showing.

Any suggestions as to what to check to find the source of this problem?
Posted
Updated 12-Dec-13 10:10am
v2
Comments
OriginalGriff 12-Dec-13 16:01pm    
Perhaps if you show us the code you are using to display the labels it might help us?
TnTinMn 12-Dec-13 16:43pm    
You mention adding "Labels", but what type of control is "n"? I am not familiar with a control that has ContainerColumn and ContainerRow properties. Is a custom control that you defined?

1 solution

This problem usually occurs because you have not set the 'BackColor Property of the Label, and not set the 'Text Property of the Label.

So, the Label takes the BackColor of its Form/ContainerControl, and, having no Text, it appears invisible even though it's there.

Rx: Set the Label 'Text Property, or make sure the BackColor is different enough from the BackColor of its Form/ContainerControl to be distinctly visible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900