我在frm_main中的放了一个panel,有一个菜单,里面有一个选项(打开)
我想单击打开,把另一个窗体(例如form1)显示在panel中,可不可以?
Form form1=new Form();
form1.Parent=this.panel2;
form1.Show();总是报错:不能将顶级控件添加到一个控件上
我不知道是什么原因????????
难道不能在panel中显示窗体吗?????
请各位大侠门帮忙
我想单击打开,把另一个窗体(例如form1)显示在panel中,可不可以?
Form form1=new Form();
form1.Parent=this.panel2;
form1.Show();总是报错:不能将顶级控件添加到一个控件上
我不知道是什么原因????????
难道不能在panel中显示窗体吗?????
请各位大侠门帮忙
public static void LoadFormToPanel( Form thisForm ,Panel panelName)
{
if ( thisForm == null )
return; if ( panelName.Controls.Count > 0 )
{
int _count = panelName.Controls.Count;
for ( int i = _count - 1; i >= 0; i -- )
{
panelName.Controls[i].Dispose();
}
} panelName.AutoScroll = true;
thisForm.Location = new Point(0,0);
thisForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
thisForm.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
thisForm.Parent = panelName;
thisForm.Visible = true;
thisForm.Dock = System.Windows.Forms.DockStyle.Fill;
thisForm.Focus();
}
#endregion
Form form1=new Form();
form1.Parent=this.panel2;
form1.Show();
form1.visible=false;不就可以实现隐藏么
在Form1的Form1_Load加入如下代码:
Form2 f=new Form2();
f.TopLevel=false;
this.panel1.Controls.Add(f);
f.Show();