C# windows程序,在运行时,怎样将第二个窗体(myfrm)加载到主窗体(如图)中间的panel上显示呢?
2个回答
展开全部
父窗体:
myFrm child = new myFrm (); //生成子窗体实例
this.panel1.Controls.Clear();
this.panel1.Controls.Add(child);//将子窗体放到panel1中
child.Show();//显示子窗体
子窗体构造函数
public myFrm ()
{
InitializeComponent();
this.TopLevel = false; //设置子窗体为非顶级窗体
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;//去掉子窗体边框
}
myFrm child = new myFrm (); //生成子窗体实例
this.panel1.Controls.Clear();
this.panel1.Controls.Add(child);//将子窗体放到panel1中
child.Show();//显示子窗体
子窗体构造函数
public myFrm ()
{
InitializeComponent();
this.TopLevel = false; //设置子窗体为非顶级窗体
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;//去掉子窗体边框
}
展开全部
通过SetParent嵌入实现!
例子:
[DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
MDIParent1 form = new MDIParent1();
SetParent(form.Handle, this.Panel1.Handle);
form.Location = new Point(0, 0);
form.Size = this.Size;
form.Show();
参考下:
http://www.cnblogs.com/icyJ/archive/2013/07/26/SetParent.html
例子:
[DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
MDIParent1 form = new MDIParent1();
SetParent(form.Handle, this.Panel1.Handle);
form.Location = new Point(0, 0);
form.Size = this.Size;
form.Show();
参考下:
http://www.cnblogs.com/icyJ/archive/2013/07/26/SetParent.html
追问
谢谢
追答
满意望采纳!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询