-1

C# ウィンドウ アプリケーションで SplitContainer ツールを使用しています

分割されたコンテナ パネルで 1 つのフォームを別のフォームに置き換えたい

これどうやってするの?

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

1 に答える 1

-1

Formに入れることはできませんPanel。フォームは、別のウィンドウに表示されることを意図しています。UserControl目的を達成するには、フォームの代わりに子孫を使用する必要があります。

于 2012-09-05T09:57:25.027 に答える