Problem in leaving form as top C #

0

I have 2 forms. The main one contains a button that opens the second form inside the main.

private void btnCalculadora_Click(object sender, EventArgs e)
    {
        Calculadora = new frmCalculadora();
        Calculadora.TopLevel = false;
        Calculadora.Visible = true;
        this.Controls.Add(this.Calculadora);
        Calculadora.Location = new Point(210, 40);
    }

However, when the secondary was opened, it was selected so that the KeyPress event of the secondary form would work, but Calculator.TopLevel = false; does not allow it.

  

Note: Leaving TopLevel = true / this.Controls.Add (this.Calculator);   of the error.

    
asked by anonymous 22.06.2017 / 18:56

1 answer

2

Place your main Form as MdiContainer , and set the MdiParent of your Secondary Form as your primary Form.

Example:

private void btnCalculadora_Click(object sender, EventArgs e)
{
    Calculadora = new frmCalculadora();
    Calculadora.MdiParent = this;
    Calculadora.Location = new Point(210, 40);
    Calculadora.Show();
}

The MdiContainer property can be defined in the Main Form, through the visual studio interface, in the Form properties window

    
22.06.2017 / 19:01