我在 C# 窗口应用程序中使用 SplitContainer 工具
我想在拆分的容器面板中将一个表单替换为其他表单
我怎样才能做到这一点?
我想在 From1 作品中完成它的工作并显示 From2.. 替换拆分容器面板的相同位置...
但是这段代码不起作用......
public partial class Parent : Form{public Parent()
{
InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = treeView1.SelectedNode;
if (node.Text.ToString().Equals("Control1"))
{
//MessageBox.Show(node.ToString());
//Control1 conr1 = new Control1();
ShowForm(1);
}
else if (node.Text.ToString().Equals("Control2"))
{
//MessageBox.Show(node.ToString());
//Control2 conr2 = new Control2();
ShowForm(2);
}
}
public void ShowForm(int id)
{
Form childObj = null;
if (id == 1)
{
childObj = new Control1();
}
else
{
childObj = new Control2();
}
childObj.TopLevel = false;
childObj.Visible = true;
childObj.Parent = this.splitContainer1.Panel2;
this.splitContainer1.Panel2.Controls.Clear();
this.splitContainer1.Panel2.Hide();
this.splitContainer1.Panel2.Controls.Add(childObj);
this.splitContainer1.Panel2.Show();
childObj.Show();
}
public Control2()
{
InitializeComponent();
}
Parent bioAdMainForm = new Parent();
private void button1_Click(object sender, EventArgs e)
{
//Control1 enrollmentForm = new Control1();
//this.Hide();
//enrollmentForm.Show();
bioAdMainForm.ShowForm(1);
}