Create Instance From String Name in C#

 you can do this using by this code:

using System.Reflection;

 

            Assembly asm = Assembly.GetEntryAssembly();

            string path = asm.GetName().ToString();

            path = path.Substring(0, path.IndexOf(","));

            string formname = path + "Your_Form_or_class_name_here";

            Type formtype = asm.GetType(formname);

            Form f = (Form)Activator.CreateInstance(formtype);

            f.Show();

 

Ebook Download
View all
Learn
View all