首页 > 代码库 > winfrom 左侧菜单
winfrom 左侧菜单
public MainForm() { InitializeComponent(); button1.Click += new EventHandler(btn_Click); button2.Click += new EventHandler(btn_Click); button3.Click += new EventHandler(btn_Click); button4.Click += new EventHandler(btn_Click); button5.Click += new EventHandler(btn_Click); leftMenu(); } private void leftMenu() { button5.Tag = button4.Tag = button3.Tag = button1.Tag = button2.Tag = 1; panel5.Visible = panel4.Visible = panel3.Visible = panel1.Visible = panel2.Visible = false; } //折叠按钮 private void btn_Click(object sender, EventArgs e) { Button btn = sender as Button; foreach (Control x in splitContainer1.Panel1.Controls) { if (x.Name == "panel" + btn.Name[btn.Name.Length - 1]) { if ((int)btn.Tag == 2) { btn.Tag = 1; x.Visible = false; return; } else { btn.Tag = 2; x.Visible = true; } break; } } int tmpUp = Convert.ToInt32(btn.Name[btn.Name.Length - 1].ToString()) - 1; int tmpDown = Convert.ToInt32(btn.Name[btn.Name.Length - 1].ToString()) + 1; foreach (Control x in splitContainer1.Panel1.Controls) { if (tmpUp != 1) { if (x.Name == "panel" + tmpUp) x.Visible = false; if (x.Name == "button" + tmpUp) x.Tag = 1; } if (x.Name == "panel" + tmpDown) x.Visible = false; if (x.Name == "button" + tmpDown) x.Tag = 1; } }
左侧菜单,2个控件一个按妞和一个面板,通过Name属性,使按钮和面板联系在一起,
winfrom 左侧菜单
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。