如图主窗体Form1 里有个splitContainer1,上部分是splitContainer1.panel1,下部分是splitContainer1.panel2.splitContainer1.panel2.中窗体下的
private void button2_Click(object sender, EventArgs e)
{ Form3 f3 = new Form3(); Form1 f1 = new Form1(); f1.splitContainer1.Panel1.Controls.Clear();
f3.TopLevel = false; f3.Parent = f1.splitContainer1.Panel1; f3.Dock = DockStyle.Fill;
f1.splitContainer1.Panel1.Controls.Add(f3);
f3.Show();}为什么Form3不能在splitContainer1.Panel1中显示出来????????
private void button2_Click(object sender, EventArgs e)
{ Form3 f3 = new Form3(); Form1 f1 = new Form1(); f1.splitContainer1.Panel1.Controls.Clear();
f3.TopLevel = false; f3.Parent = f1.splitContainer1.Panel1; f3.Dock = DockStyle.Fill;
f1.splitContainer1.Panel1.Controls.Add(f3);
f3.Show();}为什么Form3不能在splitContainer1.Panel1中显示出来????????
===========
你的所有操作都是针对新建的f1,而不是程序的当前窗体,所有对f1的操作都不会表现在程序窗体上。解决方法:把Form1 f1 = new Form1();这句删掉,所有使用f1的地方都改成this。
另外splitContainer1.Panel1.Controls.Add(f3);这句多余。
{ Form3 f3 = new Form3();
this.splitContainer1.Panel1.Controls.Clear();
f3.TopLevel = false;
f3.Parent = this.splitContainer1.Panel1;
f3.Dock = DockStyle.Fill;
this.splitContainer1.Panel1.Controls.Add(f3);
f3.Show();}
但是这个button2是在Form2中的。Form2 已经显示在Form1的splitContainer1 的Panel2中了!!!!!!!!!!