I have a flowLayoutPanel that contains a lot of panels each of which contains two labels and a button. The label I need has a name starting with lbl_, other one is label. I need to change color of all labels with name lbl_. That is not a problem if all labels will change their color. I found that I can refer to any object of first layer using foreach cycle
foreach(var label in this.Controls.OfType<Label>())
{
label.BackgroundColor = Color.Black;
}
However, when I tried code below, it didn't work. So, now I ran out of ideas
foreach (var flowlayoutpanel in this.Controls.OfType<FlowLayoutPanel>())
{
foreach (var panel in flowlayoutpanel.Controls.OfType<Panel>())
{
foreach (var label in panel.Controls.OfType<Label>())
{
MessageBox.Show("Test");
}
}
}