.NET MDIForms问题 [英] .NET MDIForms question

查看:64
本文介绍了.NET MDIForms问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MDI表格和两个子表格.如果我单击添加表单,则从一个子表单中,另一表单必须显示在MDI表单上.

I have a MDI form and two child forms. From one child form if I click add form the other form has to show on the MDI form.

namespace PHTS
{
    public partial class MainForm : Form
    {
        
     
               
        public MainForm()
        {
            InitializeComponent();
        }
		
		Form2 newMDIChild = new Form2
		newMDIChild.MdiParent = this;
       
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form1 newMDIChild = new Form1
newMDIChild.MdiParent = this;
            newMDIChild.Show();
        }
}
         
}




Form1的添加"按钮




Form1 Add button

private void addbutton_Click(object sender, EventArgs e)
        {
Form2 newMDIChild = new Form2

                newMDIChild.ShowDialog();
             this.Hide();
        }





我的问题是form2正在MDIForm之外加载.有人知道如何解决此问题.

谢谢





My problem is form2 is loading outside of the MDIForm. Can anybody knows how to fix this.

Thanks

推荐答案

将MdiParent属性设置为主表单实例-您可以从Form1 MdiParent中获取它.

但是,我建议您改为在您的子窗体中创建一个事件,该事件由父进程订阅,并让父进程创建新的子进程.这意味着每个孩子都不需要了解其他人的存在(这与OOP的想法更加一致),并且如果您认为Mdi是一个不好的选择,那么可以更轻松地更改整个系统.
Set the MdiParent property to the main form instance - you can get it from the Form1 MdiParent.

However, I would suggest that instead you create an event in your child form which the parent subscribes to, and which gets the parent to create the new child. This means that individual children don''t need to know about the existence of others (which is much more in keeping with the OOP idea) and makes it easier to change your overall system should you decide the Mdi is a bad way to go.


只需要指出代码中的错误
Just to point out the mistake in your code
private void addbutton_Click(object sender, EventArgs e)
{
    Form2 newMDIChild = new Form2();
    newMDIChild.MdiParent = this.MdiParent;
    newMDIChild.Show();
    this.Hide();
}



否则,请遵循OriginalGriff的建议.



Otherwise, follow OriginalGriff''s advise.


这篇关于.NET MDIForms问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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