日期:2014-05-19  浏览次数:20722 次

菜鸟雪地裸跪恳求高手指点。
有6个groupbox如果groupbox1显示。

单击下一个按钮。我想要groupbox2显示,groupbox1及别的groupbox都隐藏。

我的想法是   :
  for   (int   i   =   1;   i   <   7;   i++)
                        {
                                if   (((Control)( "groupBox "   +   i)).Visible   ==   true)
                                {
                                        ( "groupBox "   +   i).Visible   ==   false;
                                        ( "groupBox "   +   i+1).Visible   ==   true;
                                        break;    
                                }
                        }
可编译时总提示字符串不能转换成控件。请高手指点。



------解决方案--------------------
foreach (Control temp in this.Controls)
{
GroupBox t = temp as GroupBox;
if (t != null )
{
if (t.Name == ( "groupBox " + i))
{
t.Visible = false;
i++;
}
else
{
t.Visible = true;
}

}
}

if (i > 6)
i = 1;
------解决方案--------------------
楼上正解