我在C#窗口应用程序中使用SplitContainer工具
我想在分割的容器面板中替换其他表单的一个表单
我该怎么做?
我想在From 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);
}