日期:2014-05-16  浏览次数:20848 次

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


  这是我的代码   我想删除  里面的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);

                     } 
                }

结果如下

  希望能得到修改办法

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

public void RemoveControls(Control where)
    {
        foreach (Control c in where.Controls)
&nb