vb.net利用反射实现字符串调用窗体功能
发布时间:2020-12-17 07:48:30 所属栏目:百科 来源:网络整理
导读:VB.NET取得项目中的所有窗体名称: Dim a As Assembly = Assembly.GetExecutingAssembly '取得目前组件 ' VB.NET 反射机制取得当前函数名 类名 '类名(当前窗体名称) Dim GetClass As String = System.Reflection.MethodBase.GetCurrentMethod.ReflectedType.
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() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |