private void button1_Click(object sender, EventArgs e)
{
List<string> names = new List<string>();
foreach (var type in this.GetType().Assembly.GetTypes())
{
if (typeof(Form).IsAssignableFrom(type))
{
try
{
using (Form form = Activator.CreateInstance(type) as Form)
{
names.Add(form.Text); //names.Add(form.name)
}
}
catch
{
Console.WriteLine(string.Format("类型为 {0} 的窗体没有无参的构造函数,无法获取其名称", type));
}
}
}
}
总命名空间下所有类进行反射。