1 int panel1Height = 25; 2 int panel2Height = 200; 3 int panel3Height = 25; 4 int panel4Height = 150; 5 int panel5Height = 25; 6 int panel6Height = 100; 7 private void panel1_Click(object sender, EventArgs e) 8 { 9 if (panel2.Visible == true) //已显示容器2,需要隐藏容器2 10 { 11 panel2.Visible = false; //隐藏容器2,容器3和容器5就要移动到容器1之下 12 panel3.Top = panel1Height; //容器3移动到容器1之下 13 panel5.Top = panel1Height + panel3Height; //把容器5移动到容器3下 14 } 15 else 16 { //已隐藏容器2,需要显示容器2 17 panel2.Visible = true; //显示容器2 18 panel2.Top = panel1Height; //容器2放在容器1之下 19 panel3.Top = panel1Height + panel2Height; //容器3放在容器2之下 20 panel4.Visible = false; 21 panel6.Visible = false; 22 panel5.Top = panel1Height + panel2Height + panel3Height; //把容器5让在容器3之下 23 } 24 } 25 26 private void panel3_Click(object sender, EventArgs e) 27 { 28 panel3.Top = panel1Height; 29 if (panel4.Visible == true) 30 { 31 panel4.Visible = false; 32 panel5.Top = panel1Height + panel3Height; 33 } 34 else 35 { 36 panel4.Visible = true; 37 panel2.Visible = false; 38 panel6.Visible = false; 39 panel4.Top = panel1Height + panel3Height; 40 panel5.Top = panel1Height + panel3Height + panel4Height; 41 } 42 } 43 44 private void panel5_Click(object sender, EventArgs e) 45 { 46 panel3.Top = panel1Height; 47 panel5.Top = panel1Height + panel3Height; 48 if (panel6.Visible == true) 49 { 50 panel6.Visible = false; 51 } 52 else 53 { 54 panel6.Visible = true; 55 panel2.Visible = false; 56 panel4.Visible = false; 57 panel6.Top = panel1Height + panel3Height + panel5Height; 58 } 59 }