public void CreatForm(Form frm)
{
panel1.Controls.Clear();//清除panel里面得所有内容
frm.TopLevel = false; //取消顶级
frm.FormBorderStyle = FormBorderStyle.None;//将边框设置为无边框,无法拖动
frm.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
frm.Dock = DockStyle.Fill; //填充整个Panel容器
panel1.Controls.Add(frm); //将传进来的窗体添加到Panel容器中
frm.Show();
}
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch (treeView1.SelectedNode.Text)
{
case "xxx":
CreatForm(new unit());
break;
case "xxx":
来源:https://www.cnblogs.com/mig21/p/12455034.html