treeview中有很多个节点,如何双击节点,打开对应的窗口?

foguohf 2007-06-05 01:24:16
treeview中有很多个节点,如何双击节点,打开对应的窗口?现在想到的办法,就是使用大量的判断.
if 选择节点1 then
dim f as new form1 '创建窗口form1
else
.......

end if

但treeview的节点太多,这样下去需要写很长的代码.

如果把节点与窗口名称的对应关系记录在数据表中,通过查找数据表,就可以知道某节点对应的窗口名称,但窗口名称是一个字符串字段,不知道怎样利用这字符串字段创建窗口?

请各位高手指教,谢谢!
...全文
450 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
全国话费充值 2007-06-28
  • 打赏
  • 举报
回复
Dim tempAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
'MessageBox.Show(Form_Name(0))
Dim frm2 As Form = CType(tempAssembly.CreateInstance("Card_Users"), Form)
frm2.Show()

报错呢

有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.NullReferenceException: 未将对象引用设置到对象的实例。
在 充值卡下载管理.Card_Main.TreeView1_Click(Object sender, EventArgs e) 位置 D:\充值卡下载管理\Card_Main.vb:行号 193
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.TreeView.WmNotify(Message& m)
在 System.Windows.Forms.TreeView.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
foguohf 2007-06-05
  • 打赏
  • 举报
回复
用楼上的方法3可以了,谢谢!
‘方法3 ‘///////////////////////////////////////使用assembly.createinstance方法创建实例
Dim str As String
str = "Form2" '必须是 命名空间+点+窗体类名
Dim tempAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim frm2 As Form = CType(tempAssembly.CreateInstance(str), Form)
frm2.Show()

hy_lihuan 2007-06-05
  • 打赏
  • 举报
回复
没做过。。。
jinjazz 2007-06-05
  • 打赏
  • 举报
回复
Dim str As String



str = "Form2" '必须是 命名空间+点+窗体类名(这里假设为命名空间为空)



Dim tempAssembly As [Assembly] = [Assembly].GetExecutingAssembly()



Dim t As Type = tempAssembly.GetType(str)



Dim args() As Object = Nothing



Dim o As Object = System.Activator.CreateInstance(t, args)



CType(o, Form2).Show()



'Dim frm2 As Form = CType(tempAssembly.CreateInstance(str), Form)



'frm2.Show()


jinjazz 2007-06-05
  • 打赏
  • 举报
回复
反射
http://www.k666.com/article/743/744/756/2007/892.htm

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧