Winforms, create form instance by form name

前端 未结 2 641
后悔当初
后悔当初 2020-12-19 21:51

I need a method that returns a new instance of a form by the name of the form. Here is what I have so far:

    public Form GetFormByName(string frmname)
             


        
2条回答
  •  没有蜡笔的小新
    2020-12-19 22:45

    Assembly asm = typeof(EnterHereTypeInTheSameAssembly).Assembly;
    Type type = asm.GetType(name);
    Form form = (Form)Activator.CreateInstance(type);
    

提交回复
热议问题