Error of type System.ArgumentException with MDI forms

0

I'm doing a program in visual studio, the problem I have is that I get the following error:

  

Unhandled exception of type System.ArgumentException in    System.Windows.Forms.dll

     

Additional information: The form specified as MdiParent for   This form is not an MdiContainer container.

this is the code I am using:

agregar_productos X = new agregar_productos();
X.MdiParent = this;
X.Show();

I'm using the same code in another project and it works well, what could I be doing wrong?

    
asked by Rsh Soto 23.10.2017 в 22:32
source

1 answer

1

The problem is that you must establish your current form, from which you create the form add_products as MDI, example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        //Aquí indico que mi formulario va ser padre de otras ventanas MDI
        IsMdiContainer = true;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Este viene siendo practicamente el mismo código tuyo solo que mi formulario es de la clase Form2, por lo demás es igual
        Form2 form2 = new Form2();
        form2.MdiParent = this;
        form2.Show();
    }
}
    
answered by 23.10.2017 / 22:44
source