Click here to Skip to main content
15,907,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Everyone,

I have Created a class library(Test.dll) and added few forms.

and created windows forms application added reference to Test.dll.

In form load Created object for library and getting the form.

Test.Form1 frm=new Test.Form1();

But i want all the forms present in the dll.


Kindly help me anyone.

Thanks,
Posted
Comments
Wendelius 27-Jul-15 4:23am    
Do you mean that the Intellisense is not showing the forms to you or do you need the fetch the list of forms with code or something else?
Suvendu Shekhar Giri 27-Jul-15 4:24am    
Addded forms to a class library/dll? How did you do that?
More information required to understand your question.
Kornfeld Eliyahu Peter 27-Jul-15 4:31am    
Do you mean to find all classes inside a dll (any or only one you have created?) that represents a form?
You may use reflection or for better (plug-in like) solution MEF...
Richard MacCutchan 27-Jul-15 4:46am    
Since you created it you should know what forms are in there.

1 solution

Assuming that you want to list all the form classes in the assembly, it's not too difficult.
C#
string assemblyPath = @"D:\Temp\Test.DLL";
Assembly assembly = Assembly.LoadFrom(assemblyPath);
foreach (Type type in assembly.GetTypes())
    {
    if (type.BaseType == typeof(Form))
        {
        Console.WriteLine(type.FullName);
        }
    }

You can also use reflection to create an instance of each that's also pretty simple:
C#
string assemblyPath = @"D:\Temp\Test.DLL";
List<Form> forms = new List<Form>();
Assembly assembly = Assembly.LoadFrom(assemblyPath);
foreach (Type type in assembly.GetTypes())
    {
    if (type.BaseType == typeof(Form))
        {
        forms.Add((Form) Activator.CreateInstance(type));
        }
    }
But it's a lot easier to work with if you know the names of the forms in the assembly!
 
Share this answer
 
Comments
Bitto kumar 27-Jul-15 6:14am    
Thank you so much. i have done the same thing.
http://cboard.cprogramming.com/csharp-programming/133442-vis-csharp-expr-get-all-form-names.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900