Problem leaving form as top c#

Asked

Viewed 42 times

0

I have 2 Forms. The main 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);
    }

But I would like that when the high school was opened, he would be selected, so that the event Keypress of the secondary form functioned, but Calculator.Toplevel = false; does not allow.

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

1 answer

2


Put your Main Form as MdiContainer, and define the MdiParent from your secondary form, as your main 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 set in the Main Form by the visual studio interface in the Form properties window

  • Thank you very much!

  • gave right ? please mark as response and evaluate using the arrows on the left side of the post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.