Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > list all forms in a c# project
 

list all forms in a c# project


Hi,

How do i get a list of all the forms in a c# project in an array of some sort?

What i need to do is to show all the forms in the project in a tree navigator. Is this possible?

Thanks in advance.

Manick

manickavas  Friday, November 30, 2007 12:48 PM

Hi Manick,

The Solution Explorer has already list all form in your project, and I am not sure why you need list all the form in a project, but you can use the following code to get all form in your project and add it to a treeview.

Code Block

private void button1_Click(object sender, EventArgs e)

{

Assembly[] array = AppDomain.CurrentDomain.GetAssemblies();

foreach (Assembly a in array)

{

this.treeView1.Nodes.Add(a.GetName().Name, a.GetName().Name);

Type[] types = a.GetTypes();

foreach (Type t in types)

{

if (t.IsPublic && t.BaseType == typeof(Form))

this.treeView1.Nodes[a.GetName().Name].Nodes.Add(t.FullName);

}

}

treeView1.ExpandAll();

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Wednesday, December 05, 2007 12:59 PM

Hi Manick,

The Solution Explorer has already list all form in your project, and I am not sure why you need list all the form in a project, but you can use the following code to get all form in your project and add it to a treeview.

Code Block

private void button1_Click(object sender, EventArgs e)

{

Assembly[] array = AppDomain.CurrentDomain.GetAssemblies();

foreach (Assembly a in array)

{

this.treeView1.Nodes.Add(a.GetName().Name, a.GetName().Name);

Type[] types = a.GetTypes();

foreach (Type t in types)

{

if (t.IsPublic && t.BaseType == typeof(Form))

this.treeView1.Nodes[a.GetName().Name].Nodes.Add(t.FullName);

}

}

treeView1.ExpandAll();

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Wednesday, December 05, 2007 12:59 PM

You can use google to search for other answers

Custom Search

More Threads

• ¿Why task vision does not use Error Providers?
• Missing dll's?
• TaskVision Installation Problem
• Public Terrarium Server?
• TaskVision Source Repair/Uninstall/Reinstall Woes
• reg windows appliation deployment..
• Extending IssueVision / code group
• Sample code for PDF to TIFF
• Server Changes
• How to create web-based applications without using asp.net