Visual Basic: dynamically create objects using a string as the name

后端 未结 4 750
感动是毒
感动是毒 2020-12-06 19:25

Is there a way to dynamically create an object using a string as the class name?

I\'ve been off VB for several years now, but to solve a problem in another language,

4条回答
  •  一向
    一向 (楼主)
    2020-12-06 19:40

    Here is a really easy way I have found while rummaging through the internet:

    dynamicControl = Activator.CreateInstance(Type.GetType("MYASSEMBLYNAME." + controlNameString))
    

提交回复
热议问题