Geeks With Blogs
Saqib Ullah BootStrapper Know How
 Yesterday I wrote a piece of code that gets a list of all form types in a specific assembly. Today I share another piece of code snippet that gets list of all controls in the specific assembly form.

/// <summary>
Get list of all controls on the form.
/// </summary>
<param name="assemblyName">Assembly name.</param>
<param name="assemblyVersion">Assembly version.</param>
public void GetControlList(string assemblyName, string assemblyVersion)

   Assembly assembly = null;
   AssemblyName asmName;
    asmName = new AssemblyName();
    asmName.Name = assemblyName; //Hello.exe
   Version v = new Version(assemblyVersion);
    asmName.Version = v;
    assembly = Assembly.Load(asmName);
   Console.WriteLine("Listing all types in {0}", assembly.FullName);

     Type[] types = assembly.GetTypes();
      foreach (Type t in types)

        if (t.BaseType == typeof(System.Windows.Forms.Form))
         Form o = Activator.CreateInstance(t) as Form;
         Console.WriteLine("Form Name is {0} and Control Count are {1}", o.Name, o.Controls.Count);



Posted on Thursday, January 31, 2008 2:01 AM .Net | Back to top

Comments on this post: List of all controls in a particular form from an Assembly

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Saqib Ullah | Powered by: