创建MDI子家长表格 [英] Creating MDI child Parent forms

查看:140
本文介绍了创建MDI子家长表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工具栏上有一个mdi父表单.该表单包含显示公司详细信息(名称,地址,徽标)的面板.我需要通过单击菜单项在其上打开子窗体.当子窗体加载时,主窗体中的该面板将不可见.关闭子窗体后,应显示它.在菜单项上单击我的代码是这样的,

I have a mdi parent form with the tool bar. And that form contains panel that showing the company details (name, addresses,logo). I need to open a child form on this by clicking a menu item. When child form loads that panel in the main form should not visible. After closing the child form it should be displayed. On menu item clicked my code is like this,

panel1.Visible = false;  
form1 frm = new form1();
            
frm.MdiParent = this;
            
frm.ShowDialog(this);
panel1.Visible = true;



但是我收到错误消息不是顶级表单的表单无法显示为模式对话框.调用showDialog之前,请从任何父表单中删除该表单."



But I''m getting error "Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog."

推荐答案

这就是它:删除行"frm.MdiParent = this".在任何情况下,您都需要一个表单同时成为MDI子级和模态对话框.

谈到MDI:谁需要它?不要折磨自己,吓跑用户.
参见:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [在WPF中使用MDI窗口的问题 [ ^ ],
提供错误的MDIContainer [
This is what it is: remove the line "frm.MdiParent = this". There is no situation when you need a form to be a MDI child and a modal dialog at the same time.

Speaking of MDI: who needs it? Don''t torturing yourself and scare off your users.
See:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

—SA


在单击的项目上使用此代码.
Use this code on item clicked.
panel1.Visible = false;
form1 frm = new form1();
frm.ShowDialog();


MDIParent2_Activated event中使用以下代码.


Use the below code in MDIParent2_Activated event.

private void MDIParent_Activated(object sender, EventArgs e)
{
   panel1.Visible = true;
}


您可以创建一个派生自System.Windows.Forms.Form的自定义类.通过父母表格的参考.创建子窗体时访问构造函数.在构造函数中,使用引用隐藏父窗体.在表单关闭事件中,使用引用再次显示父表单.
You can create a custom class deriving from System.Windows.Forms.Form. Pass the parent form''s ref. to the constructor while creating the child form. In the constructor hide the parent form using reference. On form closing event show the parent form again using the reference.


这篇关于创建MDI子家长表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆