Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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 :
MSIL
private void frmparent_Load(object sender, EventArgs e)
        {
            frm_com_sel ch_com = new frm_com_sel();
            
            ch_com.ShowDialog();
            
        }


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 :

C#
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();
           
        }


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...
Posted
Updated 1-Jun-11 4:41am
v5

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
 
Share this answer
 
Comments
ankithmt 1-Jun-11 23:51pm    
Thanks bro, but I'm halfway in my project and can't go back from here...
Sergey Alexandrovich Kryukov 2-Jun-11 0:20am    
This is up to you, of course, but you should better take into account that the MDE is highly discouraged, even by Microsoft where MDE was introduced.

Good luck with your development,
--SA
You need to declare the frm_com as a form level variable, and instantiate it in the form load event like this


C#
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();
        }


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

Hope this helps
 
Share this answer
 
Comments
ankithmt 1-Jun-11 10:17am    
Thanks for your help but you didn't understand my problem...

I'm able to load form (frm_com_sel) on frmparent's load event using showdialog()

now, in that dialog (frm_com_sel), I have one button bt_add, I want to load frm_com_add as child form in MDIform (frmparent) on bt_add's click event



If i initially load frm_com_sel as child form instead of showdialog() initially then i don't have any issue but I don't want this form to lose focus unless I press 'OK'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900