从c#中的字符串调用表单

Mto*_*tok 4 c# winforms

我在C#中有一个Windows应用程序,我需要在运行时调用一个名称保存到字符串变量的表单.

喜欢;

我已经有了表格; Login.cs

string formToCall = "Login"
Show(formToCall)
Run Code Online (Sandbox Code Playgroud)

这可能吗 ?

Bra*_*tie 6

看看Activator.CreateInstance(String, String):

Activator.CreateInstance("Namespace.Forms", "Login");
Run Code Online (Sandbox Code Playgroud)

你也可以使用Assembly类(在System.Reflection命名空间中):

Assembly.GetExecutingAssembly().CreateInstance("Login");
Run Code Online (Sandbox Code Playgroud)