winfrom 左側菜單
阿新 • • 發佈:2017-07-08
ret main .cn ble convert string ring div clas
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 左側菜單