简体   繁体   English

如何获取我的应用程序中的所有表单

[英]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.

相关问题 如何在Windows Forms应用程序中编辑Word文件? - How can i edit word files inside my windows forms app? 如何获得Windows窗体应用程序已本地化为的所有语言的列表? - How do I get a list of all languages that my Windows Forms application has been localized to? 如何从我的 Api 向 Xamarin forms 应用程序发送获取请求? - How do I send a get request from my Api to a Xamarin forms app? 如何在不触碰C#应用程序的主要代码的情况下为表单及其创建的所有子表单设置默认字体? - How can i set the default font for my form and all child forms it creates, without touching the main code of the c# app? 如何仅从一种表单中更改所有表单的颜色? - How can I change the color of all my forms from just one of my forms? 如何从Facebook OAuth登录名将用户的电子邮件返回到我的asp.net网络表单应用程序? - How can I get the user's email returned to my asp.net web forms app from Facebook OAuth login? C#-如何更改所有表单上的按钮图像 - c# - how to change button image on all my forms 如何将主题应用于C#中的所有表单? - How can i apply a theme to all my forms in C#? 如何让 TopMost 发生在我所有的 Forms 上? - How do I make TopMost happen to all my Forms? 在控件内部单击时如何获得表格的鼠标位置? - How is it possible to get the forms mouse position when clicking inside a control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM