-1

I am using SplitContainer tool in C# window application

I want to replace one Form for other form in splited Container panel

How can I do this?

I want to do in From From1 works finishes it work and show From2.. replace same place of splited container panel...

but this code not working...

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);
}
John Arlen
  • 6,539
  • 2
  • 33
  • 42

1 Answers1

0

You can't place Form into Panel. Forms are intended to be displayed in separate window. You should use UserControl descendants instead of forms to achieve what you want.

Dennis
  • 37,026
  • 10
  • 82
  • 150