mercredi 30 mai 2018

How to create controls dynamically based on their type as string?

I know I can create controls using the following code:

var type = typeof(MyControl).Assembly.GetType("MyNamespace.MyControl", true);
MyControl t = Activator.CreateInstance(type) as MyControl;    

However, I have quite a few different controls that I need to create dynamically. All I have is a list of the types as string and I would like to loop through the list and create each control. So I have to remove strong-typing from the above code.

Is it possible?





Aucun commentaire:

Enregistrer un commentaire