Asf*_*sfK 1 c# controls splitcontainer winforms
我想获得splitContainer.Panel2下所有按钮和标签的背景颜色.当我尝试它时,我发现我没有成功运行任何控件(在Panel2下)我尝试这个代码:
foreach (Control c in ((Control)splitContainer.Panel2).Controls)
{
    if ((c is Button) || (c is Label))
        MessageBox.Show("Name: " + c.Name + "  Back Color: " + c.BackColor);
}
如何在splitContainer.Panel2下获取所有标签和按钮的所有背景颜色?
编辑:
你得到的消息可能是因为你有一个小组,你splitContainer.Panel2应该这样做:
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);
      }
    }
}