-2

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)

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
    }
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

1

You can use the Application.OpenForms property to get a list of all currently open forms.

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).

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291