[英]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. 大家好我想从
database
加载表单,我将表单名称作为Form1
存储在我的数据库中。 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"). 您必须提供表单的完全限定名称(“TopNamespace.SubNameSpace.Form1”),或者如果表单类驻留在除调用之外的程序集中,则必须提供AssemblyQualifiedName (“TopNamespace.SubNameSpace.Form1,MyAssembly”) )。
See the Type.GetType documentation for the details. 有关详细信息,请参阅Type.GetType文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.