从对话框表单加载(子表单到MDIform) [英] Loading a ( child form into MDIform ) from a dialog form

查看:128
本文介绍了从对话框表单加载(子表单到MDIform)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有3种表格

1. frmparent(MDI容器)
2. frm_com_sel
3. frm_com_add

我必须在frmparent的load事件上将frm_com_sel加载为对话框,以便当时无法加载其他任何形式

我有一个按钮bt_add,单击该按钮后,我想将frm_com_add作为子窗体加载到frmparent(MDIcontainer)中.

frmparent的Load事件代码:

Hello, I have 3 forms

1. frmparent (MDIcontainer)
2. frm_com_sel
3. frm_com_add

I have to load a frm_com_sel on frmparent''s load event as dialog box so that no other form can be loaded at that time

I have one button bt_add , on click of that button, i want to load frm_com_add as child form in frmparent (MDIcontainer).

frmparent''s Load event code :

private void frmparent_Load(object sender, EventArgs e)
        {
            frm_com_sel ch_com = new frm_com_sel();
            
            ch_com.ShowDialog();
            
        }



在上面的代码中,我无法为ch_com
设置MDIparent
这是frm_com_sel上bt_add按钮的代码:



In above code, i''m not able to set MDIparent for ch_com

here is the code for bt_add button on frm_com_sel :

private void bt_add_Click(object sender, EventArgs e)
        {
                frm_com_add ch_com = new frm_com_add();
                ch_com.MdiParent = PatelIndustries.frmparent.ActiveForm>
                ch_com.Show();
                ch_com.WindowState = FormWindowState.Maximized;
                this.Close();
           
        }



问题出在上面代码的粗体部分...帮我解决那一行...

或者,如果我在frmparent中将frm_com_sel加载为子窗体,则此问题已解决,但我不希望从frmparent(MDIcontainer)访问任何其他窗体,因此就像它试图失去焦点一样,它的焦点又回到了它. .

在此先感谢您,希望得到一些帮助...



Problem here is in bold part of the above code... help me out with that line...

or If I load frm_com_sel as childform in frmparent then this problem is solved but I don''t want any other form to be accessed from frmparent (MDIcontainer), so like if it tries to lose focus, its focus comes back to it...

Thanks in advance, hoping for some help...

推荐答案

想要一个好的建议来使您免于痛苦吗? 请勿使用MDI!

参见:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [提供错误的MDIContainer [
Want a good advice which saves you from suffering? Never use MDI!

See:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
MDIContainer giving error[^].

—SA


您需要将frm_com声明为表单级别变量,并在这样的表单加载事件中实例化它


You need to declare the frm_com as a form level variable, and instantiate it in the form load event like this


frm_com ch_com;
        private void frmparent_Load(object sender, EventArgs e)
        {
            ch_com = new frm_com();
        }
        private void bt_add_Click(object sender, EventArgs e)
        {
            ch_com.ShowDialog(this);
            ch_com.WindowState = FormWindowState.Maximized;
            this.Close();
        }



假定在表单属性中将frmparents IsMdiContainer设置为true.

希望对您有帮助



This assumes that frmparents IsMdiContainer is set to true in the form properties.

Hope this helps


这篇关于从对话框表单加载(子表单到MDIform)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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