VB.NET取得项目中的所有窗体名称:
Dim a As Assembly = Assembly.GetExecutingAssembly '取得目前组件 ' VB.NET 反射机制取得当前函数名 类名 '类名(当前窗体名称) Dim GetClass As String = System.Reflection.MethodBase.GetCurrentMethod.ReflectedType.Name '函数名 Dim GetFucntion As String = System.Reflection.MethodBase.GetCurrentMethod.Name '命名空间 Dim GetSystem As String = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace '从命名空间开始逐项列出 For Each t As Type In a.GetTypes '找寻组件内所有类别型态 If t.IsSubclassOf(GetType(Form)) Then '如果类别是继承自Form的话 LB.Items.Add(t.ToString & vbNewLine) '列出该类别信息 ‘TextBox1.AppendText(t.ToString & vbNewLine) End If Nextvb.net下利用反射实现字符串调用方法:
Dim AllPath As String = My.Application.Info.DirectoryPath & "\RHTEST.exe" Dim frmName As String = ListBox1.Text.Trim '窗体的类别信息(项目名.窗体名) Dim AssemblyObj As System.Reflection.Assembly AssemblyObj = System.Reflection.Assembly.LoadFile(AllPath) Dim frm As Form = AssemblyObj.CreateInstance(frmName) frm.MdiParent = Me.ParentForm frm.Dock = DockStyle.Fill frm.ShowDialog()