C# 循环删除Lable 控件的有关问题。求大神指教

C# 循环删除Lable 控件的问题。。。求大神指教
本帖最后由 u013730850 于 2014-02-27 09:56:20 编辑
C# 循环删除Lable  控件的有关问题。求大神指教C# 循环删除Lable  控件的有关问题。求大神指教

  这是我的代码   我想删除  里面的TextBox和Lable控件
 foreach (Control lbl in pxsInfo.Controls)
                {
                    MessageBox.Show(lbl.Text);
                    if (lbl  is Label)
                    {
                        pxsInfo.Controls.Remove(lbl);
                    
                    }

                    if (lbl is TextBox)
                    {
                        pxsInfo.Controls.Remove(lbl);

                    }
                }
               
                foreach (Control lbl in picImageUp.Controls)
                {
                     MessageBox.Show(lbl.Text);
                     if (lbl is Label)
                     {
                         this.picImageUp.Controls.Remove(lbl);

                     } 
                }

结果如下C# 循环删除Lable  控件的有关问题。求大神指教C# 循环删除Lable  控件的有关问题。求大神指教

  希望能得到修改办法

------解决方案--------------------
你想要的最终效果是什么
------解决方案--------------------
//调用
RemoveControls(this);

public void RemoveControls(Control where)
    {
        foreach (Control c in where.Controls)
        {
            if (lbl  is Label)
                    {
                        where.Controls.Remove(lbl);
                    
                    }

                    if (lbl is TextBox)
                    {
                        where.Controls.Remove(lbl);

                    }
if (c.Controls.Count > 0)
            {
           RemoveControls(c)
}
        }
    }
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
------解决方案--------------------
多用几种循环。。移除就行拉。。。。