急!!!!请大家江湖救急啊!!!! 在一个winform的主窗体中左侧是一个treeview控件,有固定的节点若干,现在我想实现点击左侧相应的节点然后在右侧的panel里面显示相应的窗体,我要用什么方法呢?各位老大说的详细点哈,本人已经满久没有接触winform了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 AfterSelect事件写你的代码,switch(treeview.seletecedvalue){ case "1":....break;default:...break;} “panel里面显示相应的窗体”这是没有办法实现的。你的说法有错误。在右侧的panel里你只能添加Control,而不是窗体,你可以将你的窗体改为控件,然后在添加进来,至于怎么添加,上面的各位都已经说了。只是在添加的时候要将panel里的control清空。 參考如下: TextBox textbox1 = new TextBox(); textbox1.Text = "測試動態添加控件"; textbox1.Location = new Point(10, 10); this.Controls.Add(textbox1); 谢谢黑马王子,我现在想在treeview里面得到选中的节点该怎么弄啊 private void Form1_Load(object sender, EventArgs e) { Form2 f1 = new Form2(); f1.TopLevel = false; Form3 f2 = new Form3(); f2.TopLevel=false; TreeNode td=new TreeNode(); td.Text=f1.Text; td.Tag=f1; this.treeView1.Nodes.Add(td); td = new TreeNode(); td.Text = f2.Text; td.Tag = f2; this.treeView1.Nodes.Add(td); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { Control c =(Control) e.Node.Tag; c.Show(); this.panel1.Controls.Clear(); this.panel1.Controls.Add(c); }利用TreeNode.Tag来存放相应的Form控件. using System;using System.IO;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace treeviewdemo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string path = @"C:\Documents and Settings\yf\My Documents"; listnodes(path); } private void listnodes(string path) { string [] paths=Directory.GetDirectories(path); foreach (string p in paths) { treeView1.Nodes.Add(p); listnodes(p); } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { string path = treeView1.SelectedNode.Text; string[] files = Directory.GetFiles(path); listView1.Clear(); listView1.View = View.List; foreach (string file in files) listView1.Items.Add(file); } }} 微博控制电脑--微博还有用-源码源码源码源码!给源码才给力! 如何在事件触发是选中ComboBox datagridview中的commobox列。 选择的值变了是什么事件? 如何判定鼠标在图形范围内? 急急急C#更新oracle的blob字段 窗口显示出来后,想让他自动执行一些动作该调用什么函数? 读卡程序 求MICROSOFT.NET REMOTING 权威指南,電子書下載地址,或者發給我.謝謝. 我想把WORD文档和EXCEL文件PDF文件等存储到数据库中,怎么办??用什么字段?那时示例代码?? C#比C少了什么,多了些什么 怎样验证身份证!!代码不知道哪里错了!! 再求一个正则表达式
switch(treeview.seletecedvalue)
{
case "1":....break;
default:...break;}
textbox1.Text = "測試動態添加控件";
textbox1.Location = new Point(10, 10);
this.Controls.Add(textbox1);
{
Form2 f1 = new Form2();
f1.TopLevel = false; Form3 f2 = new Form3();
f2.TopLevel=false; TreeNode td=new TreeNode();
td.Text=f1.Text;
td.Tag=f1;
this.treeView1.Nodes.Add(td); td = new TreeNode();
td.Text = f2.Text;
td.Tag = f2;
this.treeView1.Nodes.Add(td);
} private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
Control c =(Control) e.Node.Tag;
c.Show();
this.panel1.Controls.Clear();
this.panel1.Controls.Add(c);
}利用TreeNode.Tag来存放相应的Form控件.
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace treeviewdemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Documents and Settings\yf\My Documents";
listnodes(path);
}
private void listnodes(string path)
{
string [] paths=Directory.GetDirectories(path);
foreach (string p in paths)
{
treeView1.Nodes.Add(p);
listnodes(p);
}
} private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string path = treeView1.SelectedNode.Text;
string[] files = Directory.GetFiles(path);
listView1.Clear();
listView1.View = View.List;
foreach (string file in files)
listView1.Items.Add(file);
}
}
}