日期:2014-05-17 浏览次数:20962 次
private void button1_Click(object sender, EventArgs e) { panel1.Clear(); // 清空的是当前panel上的子窗体 ChildForm child = new ChildForm(); child.TopLevel = false; child.Dock = System.Windows.Forms.DockStyle.Fill; child.FormBorderStyle = FormBorderStyle.None; //child.Parent = this.panel1; this.panel1.Controls.Add(child); child.Show(); }
------解决方案--------------------
非MDI
if (panel1.Tag != null && panel1.Tag is Form) { ((Form)panel1.Tag).Close(); } Form2 frm = new Form2(); frm.TopLevel = false; frm.Parent = panel1; panel1.Tag = frm; frm.Show();