参考panel添加窗体:
http://blog.csdn.net/illegalname/article/details/65444249
http://blog.csdn.net/Eastmount/article/details/21461275
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace WindowsFormsPanel 12 { 13 public partial class Form1 : Form 14 { 15 CSUHForm2 win1 = new CSUHForm2(); 16 UHForm2 win2 = new UHForm2(); 17 CamClayForm2 win3 = new CamClayForm2(); 18 // win1 =new CSUHForm2 (); 19 //win2=new UHForm2 (); 20 //win3=new CamClayForm2 (); 21 public Form1() 22 { 23 InitializeComponent(); 24 } 25 26 private void Form1_Load(object sender, EventArgs e) 27 { 28 29 } 30 31 private void groupBox1_Enter(object sender, EventArgs e) 32 { 33 34 } 35 36 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 37 { 38 if (comboBox1.SelectedIndex > -1) 39 { 40 switch (comboBox1.SelectedItem.ToString()) 41 { 42 case "CSUH": 43 { 44 45 this.groupBox1.Controls.Clear(); 46 win1.TopLevel = false; 47 win1.FormBorderStyle = FormBorderStyle.None; 48 win1.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 49 this.groupBox1.Controls.Add(win1); // 添加w1窗体 50 win1.Show(); 51 52 this.panel1.Controls.Clear(); // 清空原有的控件 53 win1.TopLevel = false; // 非顶级窗口 54 win1.FormBorderStyle = FormBorderStyle.None; // 不显示标题栏 55 win1.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 56 this.panel1.Controls.Add(win1); // 添加w1窗体 57 win1.Show(); 58 59 } 60 61 break; 62 case "UH": 63 { 64 this.groupBox1.Controls.Clear(); 65 win2.TopLevel = false; 66 win2.FormBorderStyle = FormBorderStyle.None; 67 win2.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 68 this.groupBox1.Controls.Add(win2); // 添加w1窗体 69 win2.Show(); 70 71 this.panel1.Controls.Clear(); // 清空原有的控件 72 win2.TopLevel = false; // 非顶级窗口 73 win2.FormBorderStyle = FormBorderStyle.None; // 不显示标题栏 74 win2.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 75 this.panel1.Controls.Add(win2); // 添加w1窗体 76 win2.Show(); 77 } 78 79 break; 80 case "CamClay": 81 { 82 this.groupBox1.Controls.Clear(); 83 win3.TopLevel = false; 84 win3.FormBorderStyle = FormBorderStyle.None; 85 win3.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 86 this.groupBox1.Controls.Add(win3); // 添加w1窗体 87 win3.Show(); 88 89 this.panel1.Controls.Clear(); // 清空原有的控件 90 win3.TopLevel = false; // 非顶级窗口 91 win3.FormBorderStyle = FormBorderStyle.None; // 不显示标题栏 92 win3.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel 93 this.panel1.Controls.Add(win3); // 添加w1窗体 94 win3.Show(); 95 } 96 //dataGridView1.BackgroundColor = Color.Red; 97 break; 98 } 99 } 100 101 } 102 103 104 } 105 }