c# winform 为啥 我用treeview做得导航界面,顺序不对,望高手支招。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# winform 为啥 我用treeview做得导航界面,顺序不对,望高手支招。相关的知识,希望对你有一定的参考价值。
我用treeview做得导航界面,程序运行开始,顺序是对的,点解后,在treeview上方也是对的,比如再次点击button1,结果原来在上面的button,回到下面顺序就不对了,貌似是完全反过来了。什么原因?
代码是:
private void button2_Click(object sender, EventArgs e)
listView1.Dock = DockStyle.None;
button2.Dock = DockStyle.Top;
button1.SendToBack();
button1.Dock = DockStyle.Top;
button8.Dock = DockStyle.Bottom;
button7.Dock = DockStyle.Bottom;
button6.Dock = DockStyle.Bottom;
button5.Dock = DockStyle.Bottom;
button4.Dock = DockStyle.Bottom;
button3.Dock = DockStyle.Bottom;
listView1.BringToFront();
listView1.Dock = DockStyle.Bottom;
listView1.Clear();
listView1.Items.Add("患者治疗排班", "患者治疗排班", 3);
private void button3_Click(object sender, EventArgs e)
listView1.Dock = DockStyle.None;
button3.Dock = DockStyle.Top;
button2.SendToBack();
button2.Dock = DockStyle.Top;
button1.SendToBack();
button1.Dock = DockStyle.Top;
button4.Dock = DockStyle.Bottom;
button5.Dock = DockStyle.Bottom;
button6.Dock = DockStyle.Bottom;
button7.Dock = DockStyle.Bottom;
button8.Dock = DockStyle.Bottom;
listView1.BringToFront();
listView1.Dock = DockStyle.Bottom;
listView1.Clear();
listView1.Items.Add("设备管理", "设备管理", 4);
大家看看是什么原因????
问题很急切,忘高手支招!!! button键上去后,回不了原位,怎么回事啊???????????
难道就没有高手存在?
用一个Panel作为中介就可以了:
Button btn = new Button ();
btn.Click += new EventHandler(btn_Click);
btn.Name = "btn4";
btn.Dock = DockStyle.Bottom;
btn.Text = "4";
listView1.Controls.Add(btn);
btn = new Button();
btn.Click += new EventHandler(btn_Click);
btn.Name = "btn3";
btn.Dock = DockStyle.Top;
btn.Text = "3";
listView1.Controls.Add(btn);
btn = new Button();
btn.Click += new EventHandler(btn_Click);
btn.Name = "btn2";
btn.Dock = DockStyle.Top;
btn.Text = "2";
listView1.Controls.Add(btn);
btn = new Button();
btn.Click += new EventHandler(btn_Click);
btn.Name = "btn1";
btn.Dock = DockStyle.Top;
btn.Text = "1";
listView1.Controls.Add(btn);
//panel1.Height = 4*btn.Height;
Panel panel1= new Panel();
panel1.Name = "panel1";
panel1.Dock = DockStyle.Fill;
btn = new Button();
btn.BackColor = Color.Red;
btn.Name = "btn5";
btn.Text = "内容";
btn.Dock = DockStyle.Fill;
panel1.Controls.Add(btn);
listView1.Controls.Add(panel1);
////////////////////////////////以上是初始状态,可以在load事件里,下边是按钮事件
void btn_Click(object sender, EventArgs e)
Button btn = sender as Button;
Button btn1 =listView1.Controls["panel1"].Controls["btn1"] as Button;
if (btn1 == null)
btn1 = listView1.Controls["btn1"] as Button;
Button btn2 = listView1.Controls["panel1"].Controls["btn2"] as Button;
if (btn2 == null)
btn2 = listView1.Controls["btn2"] as Button;
Button btn3 = listView1.Controls["panel1"].Controls["btn3"] as Button;
if (btn3 == null)
btn3 = listView1.Controls["btn3"] as Button;
Button btn4 = listView1.Controls["panel1"].Controls["btn4"] as Button;
if (btn4 == null)
btn4 = listView1.Controls["btn4"] as Button;
Button btn5 = listView1.Controls["btn5"] as Button;
if (btn5 == null)
btn5 = listView1.Controls["panel1"].Controls["btn5"] as Button;
Panel panel1 = listView1.Controls["panel1"] as Panel;
//Panel panel2 = listView1.Controls["panel2"] as Panel;
if (btn1.Name == btn.Name)
listView1.Controls.Add(btn1);
listView1.Controls.Add(btn5);
btn1.Dock = DockStyle.Top;
panel1.Controls.Clear();
btn4.Dock = DockStyle.Top;
panel1.Controls.Add(btn4);
btn3.Dock = DockStyle.Top;
panel1.Controls.Add(btn3);
btn2.Dock = DockStyle.Top;
panel1.Controls.Add(btn2);
panel1.Height = 3 * btn1.Height;
panel1.Dock = DockStyle.Bottom;
btn5.Dock = DockStyle.Fill;
if (btn2.Name == btn.Name)
listView1.Controls.Add(btn2);
listView1.Controls.Add(btn1);
listView1.Controls.Add(btn5);
btn1.Dock = DockStyle.Top;
btn2.Dock = DockStyle.Top;
panel1.Controls.Clear();
btn4.Dock = DockStyle.Top;
panel1.Controls.Add(btn4);
btn3.Dock = DockStyle.Top;
panel1.Controls.Add(btn3);
panel1.Height = 2 * btn1.Height;
panel1.Dock = DockStyle.Bottom;
btn5.Dock = DockStyle.Fill;
if (btn3.Name == btn.Name)
listView1.Controls.Add(btn3);
listView1.Controls.Add(btn2);
listView1.Controls.Add(btn1);
listView1.Controls.Add(btn5);
btn3.Dock = DockStyle.Top;
btn1.Dock = DockStyle.Top;
btn2.Dock = DockStyle.Top;
panel1.Controls.Clear();
btn4.Dock = DockStyle.Top;
panel1.Controls.Add(btn4);
panel1.Height = btn1.Height;
panel1.Dock = DockStyle.Bottom;
btn5.Dock = DockStyle.Fill;
if (btn4.Name == btn.Name)
listView1.Controls.Add(btn4);
listView1.Controls.Add(btn3);
listView1.Controls.Add(btn2);
listView1.Controls.Add(btn1);
listView1.Controls.Add(btn5);
btn1.Dock = DockStyle.Top;
btn2.Dock = DockStyle.Top;
btn3.Dock = DockStyle.Top;
btn4.Dock = DockStyle.Top;
panel1.Controls.Add(btn5);
panel1.Dock = DockStyle.Fill;
//panel1.Height =btn1.Height;
//panel1.Dock = DockStyle.Bottom;
btn5.Dock = DockStyle.Fill;
///////我用btn5代替了其他四个按钮标签下的内容,你可以自己改改。。。
参考技术A 费解啊 费解追问哥们 帮帮忙呗
追答你的控件完全是手动处理的啊,你在写那个button1和button2的停靠样式的时候,按照顺序写,不要先2后1的,都按照123456的顺序走。
好运!
C# winform开发中,如果treeview的节点太多,导致加载很慢,怎么做可以提给效率?
treeview菜单加载慢的原因有很多。如果确定是节点多引起的问题,可以考虑上面所说的先加载一部分数据。节点如果太多,可以考虑换一个UI设计。如果不确定是节点多引起的问题,那么就要考虑数据库操作,数据库设计和实现代码方面的问题了。这一点在生成无限树(区分目录和节点)时,也很重要。我认为因为节点太多导致速度慢的可能性还是相对小一些的。毕竟既然用treeview,就说明不可能是几百上千的节点(节点太多,用户操作的确是个很大的问题)。如果有这么多,就应该考虑修改UI了。 参考技术A 既然用.NET开发程序,那么教你一招:延迟加载就是用到的时候,再去加载需要的东西那么就可以这样做1.加载第一级的TreeNode节点2.当用户想展开某一TreeNode的时候,如果此节点的子节点没有加载,那么请如同第1条,加载此节点的子节点. 这样就不会因为级数多,导致加载很慢, 其实任何语言都适用,数据量大的时候,最好的选择就是延迟加载 参考技术B 你可以选择分配加载,即先加载父节点类型的数据,然后点击展开按钮的时候再加载子节点的数据。 参考技术C 开始只加载一级节点,当点击某一节点时再加载对应的二级节点,以此类推加载其他级别节点。以上是关于c# winform 为啥 我用treeview做得导航界面,顺序不对,望高手支招。的主要内容,如果未能解决你的问题,请参考以下文章
c#的winform TreeView控件中,展开不同的节点,右边显示不同的内容,该怎么做啊,请帮帮我吧,谢谢~