How to get an instance of a form through a form name (string)?

zhaozj2021-02-16  50

Method 1 (REFLECTION):

Dim str As Stringstr = "myTest.Form2" 'must be namespace p form class name Dim tempAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly () Dim frm2 As Form = CType (tempAssembly.CreateInstance (STR), FORM) fr2.show ()

Method 2 (Type.gettype ()):

Dim frmName, fullName As String frmName = "form2" fullName = Application.ProductName & "." & FrmName Dim frm2 As Form frm2 = Activator.CreateInstance (Type.GetType (fullName, True, True)) frm2 .Visible = True

转载请注明原文地址:https://www.9cbs.com/read-20549.html

New Post(0)