我使用SplitContainer的工具,在C#窗口应用程序
我想更换一个表格等形式splited集装箱板
我怎样才能做到这一点?
我想在从1跳转工程完成它的工作,并显示From2 ..更换splited容器板相同的地方......
但这code不工作...
公共部分类家长:表格{公共父()
{
的InitializeComponent();
}
私人无效treeView1_AfterSelect(对象发件人,TreeViewEventArgs E)
{
树节点节点= treeView1.SelectedNode;
如果(node.Text.ToString()。等于(控制1))
{
//MessageBox.Show(node.ToString());
//控制1 conr1 =新的控制1();
ShowForm(1);
}
否则,如果(node.Text.ToString()。等于(控制2))
{
//MessageBox.Show(node.ToString());
//控制2 CONR2 =新的控制2();
ShowForm(2);
}
}
公共无效ShowForm(INT ID)
{
形成childObj = NULL;
如果(ID == 1)
{
childObj =新的控制1();
}
其他
{
childObj =新的控制2();
}
childObj.TopLevel = FALSE;
childObj.Visible =真;
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();
}
公共控制2()
{
的InitializeComponent();
}
家长bioAdMainForm =新的父();
私人无效的button1_Click(对象发件人,EventArgs的)
{
//控制1 enrollmentForm =新的控制1();
//this.Hide();
//enrollmentForm.Show();
bioAdMainForm.ShowForm(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);
}
解决方案
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.
下一篇:与ReferenceLoopHandling.Ignore连载循环依赖ISerializable的对象时StackOverflowException被抛出抛出、对象、Ignore、ReferenceL