这样改——
if (re) // 末创立,建立子窗体
{
string ss = "Form";
Type[] ts = Assembly.GetExecutingAssembly().GetTypes();
for(int i=0;i< ts.Length;i++)
{
if(ts[i].Name == str)
{
ss = ts[i].FullName;
}
}
Form temp_form = (Form)(Assembly.GetExecutingAssembly().CreateInstance(ss));
if (temp_form != null)
{
temp_form.MdiParent = this;
temp_form.Name = str;
temp_form.Text = str;
temp_form.Show(); }
}
if (re) // 末创立,建立子窗体
{
string ss = "Form";
Type[] ts = Assembly.GetExecutingAssembly().GetTypes();
for(int i=0;i< ts.Length;i++)
{
if(ts[i].Name == str)
{
ss = ts[i].FullName;
}
}
Form temp_form = (Form)(Assembly.GetExecutingAssembly().CreateInstance(ss));
if (temp_form != null)
{
temp_form.MdiParent = this;
temp_form.Name = str;
temp_form.Text = str;
temp_form.Show(); }
}
就是双击节点A,弹出FomrA;双击节点B,弹出FomrB;
以下是我的代码,分很少就只给你个实现的代码,方法不太好,还有点Bug,应该用抽象工厂做,
不过这样也可以达到你的要求了应该。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
Form fr = null;
if (e.Node.Name == "节点A")
{
fr = new FormA();
}
else if (e.Node.Name == "节点B")
{
fr = new FormB();
}
else
{
fr = new FormC();
}
fr.Show();
}
}
}