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

爱的人是你 2014-02-27 09:51:59


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

}
}

结果如下

希望能得到修改办法
...全文
180 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
多用几种循环。。移除就行拉。。。。
爱的人是你 2014-02-27
  • 打赏
  • 举报
回复
看小是不是这里的问题
爱的人是你 2014-02-27
  • 打赏
  • 举报
回复
foreach (Control lbl in pxsInfo.Controls) { MessageBox.Show(lbl.Text); pxsInfo.Controls.Remove(lbl); //if (lbl is Label) //{ // pxsInfo.Controls.Remove(lbl); //} //if (lbl is TextBox) //{ // pxsInfo.Controls.Remove(lbl); //} } 这样都不行,,,,
爱的人是你 2014-02-27
  • 打赏
  • 举报
回复
兄弟 这个不行 。。。。
feiyun0112 2014-02-27
  • 打赏
  • 举报
回复
//调用
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/
爱的人是你 2014-02-27
  • 打赏
  • 举报
回复
删除控件中的Lable TextBox
低姿态微笑 2014-02-27
  • 打赏
  • 举报
回复
你想要的最终效果是什么
爱的人是你 2014-02-27
  • 打赏
  • 举报
回复





这是右边的图

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧