如果你的项目是用wince开发并且机器是小型的pda,你可以考虑有这种布局方式。
IDE上布局,如图
1 /// <summary> 2 /// 显示层 3 /// </summary> 4 /// <param name="name"></param> 5 private void ShowPnl(string name) 6 { 7 foreach (Control c in this.Controls) 8 { 9 if (c is Panel && !String.Equals(c.Name, name)) 10 { 11 Panel p = (Panel)c; 12 p.Visible = false; 13 } 14 else if (c is Panel && String.Equals(c.Name, name)) 15 { 16 Panel p = (Panel)c; 17 p.Visible = true; 18 p.Location = new Point(0, 16); 19 } 20 } 21 pnlTopBar.Visible = true; 22 if (!String.Equals(name, "pnlLogin")) 23 { 24 pnlButtomBar.Location = new Point(0, 300); 25 pnlButtomBar.Visible = true; 26 } 27 }
1 /// <summary> 2 /// 添加所有层里面的按钮点击事件 3 /// </summary> 4 private void LoadBtnClick() 5 { 6 foreach (Control c1 in this.Controls) 7 { 8 if (c1 is Panel) 9 { 10 foreach (Control c2 in c1.Controls) 11 { 12 if (c2 is Button) 13 { 14 c2.Click += new EventHandler(btn_Click); 15 } 16 } 17 } 18 } 19 } 20 /// <summary> 21 /// Button事件 22 /// </summary> 23 /// <param name="sender"></param> 24 /// <param name="e"></param> 25 void btn_Click(object sender, EventArgs e) 26 { 27 Button btn = sender as Button; 28 btn.Enabled = false; 29 switch (btn.Name) 30 { 31 case "btnLogin": 32 case "btnMain_ButtomBar": 33 ShowPnl(pnlMain.Name); 34 break; 35 case "btnShowPnl1": 36 case "btnShowPnl1_ButtomBar": 37 ShowPnl(pnl1.Name); 38 break; 39 case "btnShowPnl2": 40 case "btnShowPnl2_ButtomBar": 41 ShowPnl(pnl2.Name); 42 break; 43 case "btnShowPnl3": 44 case "btnShowPnl3_ButtomBar": 45 ShowPnl(pnl3.Name); 46 break; 47 case "btnShowPnl4": 48 case "btnShowPnl4_ButtomBar": 49 ShowPnl(pnl4.Name); 50 break; 51 case "btnLoginOut": 52 ShowPnl(pnlLogin.Name); 53 break; 54 default: 55 break; 56 } 57 btn.Enabled = true; 58 }
Demo地址:XyzDemoPro