winform(c#)关于treeview打开多个panel的问题,急!
我需要做一个小软件,用一个splitcontainner把form1界面分成左右。左边放一个treeview1,有四个主节点,没有子节点,把四个节点的text分别设成“0”,“1”,“2”,”3“。右边放了四个panel,并且dock都是fill.我想每次点击一个节点显示对应的一个panel的内容。我的程序如下:private void treeView1_AfterSelect (objectsender,TreeViewEventArgs e)
{
switch(treeView1.SelectedNode.Text.ToString())
{
case "0":
panel1.Visible=true;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
break;
case "1":
panel2.Visible=true;
panel1.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
break;
case "2":
panel3.Visible = true;
panel1.Visible = false;
panel2.Visible = false;
panel4.Visible = false;
break;
case "3":
panel4.Visible = true;
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
break;
}
}
但是每次执行时就只有点击第一个节点时第一个要显示的Panel显示出来,点其它三个节点,没有反应,相应的panel不会被显示。请问,我这个小程序错在哪里,或者是缺少什么?多谢了,我对c#编程不熟,我郁闷好长时间了!能不能帮帮我?多谢了!
--------------------编程问答-------------------- 有做过这种软件的请告诉我好吗?小妹在此先谢了!或者有更好的想法也可以告诉我,因为我才c#不怎么样,多谢了! --------------------编程问答-------------------- 请问有明白的吗?多谢了,在线等·! --------------------编程问答-------------------- 这段代码没有问题...
请检查TreeView1的node的Text属性是否正确...
还有就是...你显示效果用的Panel....你是怎么确定Panel显示是否正确的...
另外...要注意的一点就是....在设置右边的4个Panel时...别把Panel拖到Panel里面去了.... --------------------编程问答-------------------- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch (treeView1.SelectedNode.Text.ToString())
{
case "0":
panel1.Visible = true;
panel1.Dock = System.Windows.Forms.DockStyle.Fill;
panel2.Dock = System.Windows.Forms.DockStyle.None;
panel3.Dock = System.Windows.Forms.DockStyle.None;
panel4.Dock = System.Windows.Forms.DockStyle.None;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
break;
case "1":
panel2.Visible = true;
panel2.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Dock = System.Windows.Forms.DockStyle.None;
panel3.Dock = System.Windows.Forms.DockStyle.None;
panel4.Dock = System.Windows.Forms.DockStyle.None;
panel1.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
break;
case "2":
panel3.Visible = true;
panel3.Dock = System.Windows.Forms.DockStyle.Fill;
panel2.Dock = System.Windows.Forms.DockStyle.None;
panel1.Dock = System.Windows.Forms.DockStyle.None;
panel4.Dock = System.Windows.Forms.DockStyle.None;
panel1.Visible = false;
panel2.Visible = false;
panel4.Visible = false;
break;
case "3":
panel4.Visible = true;
panel4.Dock = System.Windows.Forms.DockStyle.Fill;
panel2.Dock = System.Windows.Forms.DockStyle.None;
panel3.Dock = System.Windows.Forms.DockStyle.None;
panel1.Dock = System.Windows.Forms.DockStyle.None;
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
break;
}
} --------------------编程问答-------------------- case语句中不用设置visible属性吧,可以直接调用PanelX.BringToFront()
显示PanelX。 --------------------编程问答-------------------- 断点看看 --------------------编程问答-------------------- de易做图t:
break;
应该有影响
--------------------编程问答-------------------- 你是不是 不小心把panel2、panel3、panel4添加到panel1里面了,作为panel1的子控件了
看看自动生成的代码
补充:.NET技术 , C#