I want to get the background color of all buttons and labels under splitContainer.Panel2. When I try it I discover I not success to run on any control (under Panel2) I try this code:
foreach (Control c in ((Control)splitContainer.Panel2).Controls)
{
if ((c is Button) || (c is Label))
MessageBox.Show("Name: " + c.Name + " Back Color: " + c.BackColor);
}
How can I get all background colors of all labels and buttons under splitContainer.Panel2 ?
EDIT:
you get the message probably because you have a panel under your splitContainer.Panel2
and should do:
foreach (Control c in ((Control)splitContainer.Panel2).Controls)
{
if(c is Panel)
{
foreach (Control curr in c.Controls)
{
MessageBox.Show("Name: " + curr.Name + " Back Color: " + curr.BackColor);
}
}
}