简体   繁体   中英

Loading a Form with out its instance

Hi all I would like to get the form loaded from the database , I am storing my form name as Form1 in my DB. Now I would like to get this form name on the other form button click event I tried as follows by storing the form name in a string but I am unable to load the form can some one help me

string strFromName="Form1";
Type type = Type.GetType(strFromName); // Null reference is coming here
Form form = (Form)Activator.CreateInstance(type);

从程序集中获取所有类型,并在获得instatnce类型后,通过名称将实例与字符串“Form1”进行比较

You have to supply the fully qualified name of the form ("TopNamespace.SubNameSpace.Form1") or if the form class is residing in an Assembly other than the calling you have to supply an AssemblyQualifiedName ("TopNamespace.SubNameSpace.Form1,MyAssembly").

See the Type.GetType documentation for the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM