单击树节点在父窗体中打开了几个子窗体,如何做到我选中节点后打开对应的子窗体???

YYJAH 2007-11-08 10:27:20
单击树节点在父窗体中打开了几个子窗体,如何做到我选中节点后打开对应的子窗体???
-节点0
---A
---B
---C
选中节点A,弹出FORM1
选中节点B,弹出FORM2
选中节点C,弹出FORM3
我的代码如下,但是只能打开同一下窗体,如何实现点击不同节点后显示相应的窗体呢
private void trwFuncFrame_AfterSelect_1(object sender, TreeViewEventArgs e)
{
System.String str = trwFuncFrame.SelectedNode.Text;//取得相应treeview结点的text值

bool remark = true;

for (int i = 0; i < this.MdiChildren.Length; i++)

if (this.MdiChildren[i].Name.Equals(str)) //查看有没有相同的MDI子窗体
{

this.MdiChildren[i].Activate(); //子窗体已经被创立,激活它

remark = false;

break;

}



if (remark) // 末创立,建立子窗体
{

MyForm.frmDBConnect temp_form = new MyForm.frmDBConnect();
temp_form.MdiParent = this;
temp_form.OnFormMinSize += new MyForm.frmDBConnect.FormMinSize(form_OnFormMinSize);
temp_form.Name = str;
temp_form.Text = str;
temp_form.Show();


}
}
...全文
132 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxing2006 2007-11-09
  • 打赏
  • 举报
回复
楼主你的代码是正确的
Arthur_qi 2007-11-09
  • 打赏
  • 举报
回复
哦对了,用反射是最好的,抽象工厂,和反射,以后有了变化也好维护
Arthur_qi 2007-11-08
  • 打赏
  • 举报
回复
不知道我理解的对不对;
就是双击节点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();
}
}
}
XMUMEEameng 2007-11-08
  • 打赏
  • 举报
回复
这样改——
if (remark) // 末创立,建立子窗体
{
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();

}

}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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