Mtok Mtok - 1 year ago 87
C# Question

Calling a form from a string in c#

I have a Windows Application in C# and I need to call a Form whose name is saved into a string variable in run-time.


I already have the form; Login.cs

string formToCall = "Login"

Is this possible ?

Answer Source

Have a look at Activator.CreateInstance(String, String):

Activator.CreateInstance("Namespace.Forms", "Login");

you can also use the Assembly class (in System.Reflection namespace):

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download