怎么遍历工程下的所有Form?

danjiewu 2006-11-10 10:34:01
问题是这样的,需要吧工程下所有Form中的所有控件的名字列出来,现在主要是要列出所有的Form,怎么做才能实现?
...全文
233 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lldwolf 2006-11-10
  • 打赏
  • 举报
回复
一楼正解
yeerh 2006-11-10
  • 打赏
  • 举报
回复
同意Axlong(爱心龙龙)
用反射
superxiaomm 2006-11-10
  • 打赏
  • 举报
回复
FindwindowEx可以拿到子窗体
Axlong 2006-11-10
  • 打赏
  • 举报
回复
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

Type[] types = assembly.GetTypes();
foreach( Type t in types )
{
if( t is Form )
//you can create a instance to do something,like :
{
Form frm = Activator.CreateInstance( t );
frm.Show();
}
}
raozhiven 2006-11-10
  • 打赏
  • 举报
回复
to:sql5186(sql5186)

很报歉,没能查到相关资料。你能运行你的代码看到效果吗?
sql5186 2006-11-10
  • 打赏
  • 举报
回复
to:raozhiven(朗屹)
你能查查资料再说话吗?
raozhiven 2006-11-10
  • 打赏
  • 举报
回复
一楼的应该错了吧

t is Form????

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

Type[] types = assembly.GetTypes();
foreach (Type t in types)
{
if (t.IsAssignableFrom(typeof(System.Windows.Forms.Form))) //*******************
//you can create a instance to do something,like :
{
System.Windows.Forms.Form frm = Activator.CreateInstance(t);
frm.Show();
}
}
jedliu 2006-11-10
  • 打赏
  • 举报
回复
一楼的不错!
让我再想想有没有更好的!

111,098

社区成员

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

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

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