在panel中加载form的例子

我们可以把子窗体当成一个控件,设置Dock属性不就行了吗?

赶快测试一下:

private void button1_Click(object sender, EventArgs e)
           {

               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();
           }

你可能感兴趣的:(C#)