在C#中如何实现点击左边的treeview的节点,右边显示相应的界面?右边的界面应该用什么东西做呢?很多人说用panel,可是如果节点很多的话,那不是会有很多panel?我本意是想,每个节点的界面都是单独的winform,然后加载到右边的panel里面,可是运行之后根本不显示加载的窗体啊。请高手帮忙。。
解决方案 »
- 如何只要短日期?
- [求助]百度地图 已知坐标,如何从上百万数据中查询 距离20公里内的坐标。
- vs2010中没有arraylist吗?
- WebBrowse控件的Refresh函数能否反复执行?
- 用Timer怎么不能更新TextBox值?
- 我写了一个自定义web控件(注意,不是usercontrol),里面有一个集合属性,请问如何才能够实现代码自动提示。
- 今天圣诞了,节日快乐咯,散点分,顺路问个小问题!!!
- 枚举什么时候使用?好象能使用IF ELSE代替
- c#是否有可能获取控件的某一位置的像素?
- 需要一个高效算法模型
- 高人帮帮忙啊,还是低版本.net调用高版本.net程序
- 关与if与switch效率问题
每一个节点对应一个url,效果不是传统的frame,是刷新全页面可以放在母版页里,不同的内容页使用即可
可是为什么我加载了之后,并不显示呢。代码如下: private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (treeView1.SelectedNode.Text == "权限管理")
{
Form4 f4 = new Form4();
f4.TopLevel = false;
panel2.Controls.Clear();
panel2.Controls.Add(f4);
}
}
判断取到的是第几级结点,然后 formX.Show... X 是1\2\3\4...
{
if (e.Node.Name == "节点0")
{
SettingForm1 stfrm1 = new SettingForm1();
stfrm1.TopLevel = false;
stfrm1.FormBorderStyle = FormBorderStyle.None;
stfrm1.WindowState = FormWindowState.Maximized;
panel1.Controls.Add(stfrm1);
stfrm1.Show();
}
}
这样就可以了!
这个的前提还是必须是treeview所在的窗体是父窗体吧。
form1.TopLevel = false;
panel1.Controls.Add(form1);
form1.Show();点击treeview是先检索panel1上的Controlss是否为0,不是0,就全部关闭
关闭不用我再说了吧
- -好像是这个原因,偶现在show了窗体之后就显示了。还有一个问题,可以把treeview放在splitContainer里面么。偶刚才试了一下,发现窗体又不显示了喔。望解答。
必须在splitContainer1.Panel2上放一个独立的Panel才行!splitContainer1.Panel2的类型是:SplitterPanel不是Panel!
Form的左边是TreeView,右边是Panel,而把每个界面定义一个UserControl,TreeView节点点击之后,动态设置UserControl到Panel不就完了。弹那么多Form用户体验很差的,所有的东西在一个Form当中搞定。
是在splitContainer.panel2上面放的一个panel,可是窗体还是不显示,之前的代码需要改什么地方么?
我就是这个意思啦,点击节点的时候,加载form到panel里面显示,是这样么?
userControl是什么?学习!!
url是你treeview被选中节点的属性值TreeNode tn = this.treeView1.SelectedNode;
string url = "";
if (tn.Tag != null)
{
url = tn.Tag.ToString();
webBrowser1.Navigate(url);
}
Tag存储url
userControl应该是用户控件吧,但是具体做法不会,烦请指教。
偶现在明白了,之前的问题是因为没show。不过有朋友跟贴说这种方法并不好。期待他回贴呢。
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
class MainForm:Form
{
private TreeView treeView1;
private Panel panel1; public MainForm()
{
this.InitializeComponent(); LoginInDialog login = new LoginInDialog();
this.treeView1.Nodes[0].Tag = login; WelcomeDialog welcome = new WelcomeDialog();
this.treeView1.Nodes[1].Tag = welcome;
}
private void InitializeComponent()
{
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("Welcome");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("Login");
this.treeView1 = new System.Windows.Forms.TreeView();
this.panel1 = new System.Windows.Forms.Panel(); this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
treeNode1.Name = "Node0";
treeNode1.Text = "Welcome";
treeNode2.Name = "Node1";
treeNode2.Text = "Login";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode1,
treeNode2});
this.treeView1.Size = new System.Drawing.Size(188, 380);
this.treeView1.TabIndex = 0;
this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
this.Controls.Add(this.treeView1); this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(194, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(358, 380); this.ClientSize = new System.Drawing.Size(552, 380);
this.Controls.Add(this.panel1);
this.Controls.Add(this.treeView1);
this.Name = "MainForm";
this.ResumeLayout(false);
} private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
this.panel1.Controls.Clear();
this.panel1.Controls.Add(e.Node.Tag as Control);
}
}
class WelcomeDialog:UserControl
{
public WelcomeDialog()
{
this.InitializeComponent();
} #region Component Designer generated code private void InitializeComponent()
{
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(117, 19);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(111, 13);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "http://www.csdn.net/"; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(19, 19);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Welcome to:"; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(19, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(277, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Copyright © 1999-2010, CSDN.NET, All Rights Reserved"; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.linkLabel1);
this.Name = "WelcomeDialog";
this.Size = new System.Drawing.Size(299, 269);
} #endregion private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
class LoginInDialog:UserControl
{
public LoginInDialog()
{
this.InitializeComponent();
} private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox(); this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(31, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 0;
this.label1.Text = "UserName:";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(34, 77);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Password:"; this.textBox1.Location = new System.Drawing.Point(113, 28);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(130, 20);
this.textBox1.TabIndex = 2;
this.textBox2.Location = new System.Drawing.Point(113, 70);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(130, 20);
this.textBox2.TabIndex = 2; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "LoginInDialog";
this.Size = new System.Drawing.Size(297, 262);
}
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
}
}
一样的方法没变!
还是对panel1添加form:
panel1.Controls.Add(stfrm1);
stfrm1.Show()
每一个功能块都是一个UserControl,点击Tree的时候,就可以实例化一个UserControl了。
userControl不会用。55555.
呵呵,这明明是form的边界嘛:
在同一个Form1里,可以改变如下属性:
Form1.ActiveForm.Width = x + y;
x是原先的width值
y是增量,也就是你的treeview的宽度,或panel的宽度
这样的话,就在一个Form1里了(也就没有了子窗体一说了)
具体实现:
做个按钮,宽度做到最小,3(?)个像素单位,高度适中,按一下,width+=y,再按一下,width-=y.
是这样的业务吗?
第一次发贴,谢谢大家的热情,不知道结贴之后还能不能回贴,不能的话可以加偶的QQ:806905.注明:csdn.