C# Get form names of project A from Project B

后端 未结 3 807
我寻月下人不归
我寻月下人不归 2021-01-26 11:02

I have two Projects in one solution, project A and project B (using VS2010 Ultimate and C# windows application). Project B ac

3条回答
  •  星月不相逢
    2021-01-26 11:53

    Try This Code:

     private void GetFormNames()
        {
    
    
            Type[] AllTypesInProjects = Assembly.GetExecutingAssembly().GetTypes();
                for (int i = 0; i < AllTypesInProjects.Length; i++)
                {
                    if (AllTypesInProjects[i].BaseType == typeof(Form))
                    {            /* Convert Type to Object */
                        Form f = (Form)Activator.CreateInstance(AllTypesInProjects[i]);
                        string FormText = f.Text; 
                        listBox1.Items.Add(FormText);
                    }
                }
    
        }
    

提交回复
热议问题