Form that was specified to be the MdiParent for this form is not an MdiContainer
Asked Answered
H

5

9

I was working on an inventory software and suddenly came to know that I need some main form through which I should open all the other forms, so I created one named frmMainPanel and use a menu strip to link it to another I am successful in linking them but they are opening outside the main form, I use following code to link them

Linking frmSaleInvoice form using:

frmSaleInvoice childForm = new frmSaleInvoice();
cs.show()

now i realize i should make them child to the main form so i tried that using following code:

frmSaleInvoice childForm = new frmSaleInvoice();

childForm.MdiParent = this;
childForm.Show();

but it says **" Form that was specified to be the MdiParent for this form is not an MdiContainer."**

can any one help me out wher i am mistaking and how could i make a form named frmSaleInvoice to child of other form named frmMainPanel

Headmaster answered 24/3, 2014 at 19:50 Comment(0)
W
29

The Mdi parent must have it's IsMdiContainer property set to True. You can set this property at design time in your frmMainPanel form.

Which answered 24/3, 2014 at 19:55 Comment(3)
I already set the IsMdiContainer property to true, but the error is still persisting.Shadbush
@Shadbush I feel silly for asking but you did set IsMdiContainer to true for the PARENT form?Which
What if the Main Form isMDIContainer and still thrown error? Note: My MainForm Loads Forms from FormManager ClassWatcher
Z
9

You should set the IsMdiContainer = true for the parent form.

Zippy answered 24/3, 2014 at 19:55 Comment(0)
C
0

you don't have to set the childForm to true, you can try this:

childForm.MdiParent = (name of your mdiparent form).ActiveForm;
childForm.Show();
Continue answered 15/6, 2016 at 6:57 Comment(0)
R
0

Just write IsMdiContainer = true; in your code.

Form2 fL = new Form2();
fL.MdiParent = this;
fL.Show();

Form2 is the name of the form that you want to show.

Ratoon answered 20/2, 2018 at 11:49 Comment(0)
S
0
private void tsbCadastrar_Click(object sender, EventArgs e)
    {
        try
        {
            frmCliente cliente = null;
            foreach (Form frm in this.MdiChildren)
            {
                if (frm is frmCliente)
                {
                    cliente = (frmCliente)frm;
                    break;
                }
            } 
            if (cliente == null)
            {
                cliente = new frmCliente();
                cliente.MdiParent = this; //Remove this line in case the IsMdiParent = True 
                cliente.Show();
            }
            cliente.Focus();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Não foi possivel se conectar ao formulario devido ao erro: " + ex.Message,
                "Aviso",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information);
        }
    }
Succulent answered 23/10, 2019 at 18:6 Comment(2)
Hope it´s usefullSucculent
While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Shipload

© 2022 - 2024 — McMap. All rights reserved.