[英]How to get all the forms inside my app
I need to get all the forms inside my c# application and add the .Text parameter for each one to a combobox control and i need to do all in one method (void)我需要在我的 c# 应用程序中获取所有表单并将每个表单的 .Text 参数添加到组合框控件中,我需要在一个方法中完成所有操作(无效)
myCode:我的代码:
System.Reflection.Assembly[] assembly = AppDomain.CurrentDomain.GetAssemblies();
foreach(System.Reflection.Assembly asem in assembly)
{
foreach(Type t in asem.GetTypes())
{
ComboBox1.Items.Add(t.Name);
//here i need to get the .Text param
//where Name is the Form name
}
}
You can use the Application.OpenForms
property to get a list of all currently open forms.您可以使用Application.OpenForms
属性获取所有当前打开的表单的列表。
You cannot iterate all the types since you don't get the running instances but only the types.您无法迭代所有类型,因为您没有获得正在运行的实例,而只有类型。 If you don't have an instance of a class, the class does not exist in memory.如果您没有类的实例,则该类不存在于内存中。
(Just because a class is instantiated does not mean that it has a visual appearance, even if the class derives from Form
). (仅仅因为一个类被实例化并不意味着它具有视觉外观,即使该类派生自Form
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.