如何遍历窗体上所有的Components ,并得到Component的类型?

海淀网友 2004-09-25 11:41:47
如何遍历窗体上所有的Components ,并得到Component的类型。
...全文
194 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
icesnows 2004-10-14
  • 打赏
  • 举报
回复
应该修正一下
foreach (Component NextComponent in this.components.Components)
{
Type myType = NextComponent.GetType();
//进行处理
}
其中components是在form中声明的一个IContainer对象
icesnows 2004-10-14
  • 打赏
  • 举报
回复
是不是可以这样:
ComponentCollection components = this.Components;
foreach (Component NextComponent in components)
{
Type myType = NextComponent.GetType();
//进行处理
}
tashanzhishi 2004-10-14
  • 打赏
  • 举报
回复
foreach (Control conSel in this.Controls)
{
if (conSel is TextBox)
{
////...
}
else if (conSel is DateTimePicker)
{
////...
}
....
}
jinbingg 2004-10-14
  • 打赏
  • 举报
回复
foreach (Control myControl in this.grpRole.Controls )
{
if (myControl.GetType()==this.chk1.GetType())
{
((CheckBox)myControl).Checked=false;
}
}
这个是遍历的。得到类型我不会阿。。
海淀网友 2004-10-14
  • 打赏
  • 举报
回复
最近回老家了,刚回来,自己顶一下

110,567

社区成员

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

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

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