日期:2014-05-20 浏览次数:21057 次
private void button1_Click(object sender, EventArgs e)
{
Assembly a = Assembly.LoadFile(Application.ExecutablePath);
Type[] types = a.GetTypes();
foreach (Type t in types)
{
if (t.BaseType.Name == "Form")
{
Form f = (Form)Activator.CreateInstance(t, true);
if (f != null)
{
foreach (Control c in f.Controls)
{
MessageBox.Show(c.Name);
}
}
}
}
}
------解决方案--------------------
还要考虑
如果窗口是继承了多次From就不仅仅是判断BaseType属性了,有可能是BaseType.BaseType. ...
如果那个窗体没有无参数的构造函数,Activator.CreateInstance执行是个问题。