Parent form superimposing child form C#

Asked

Viewed 141 times

3

I’m developing a Windows Forms application in Visual Studio and I’m having a hard time.

I put the parent form to Ismdicontainer and instead of adding Toolbox, I made a form only with buttons, it happens that when clicking the button and open the child form, the parent form overlaps the child.

Formulário pai

Formulário filho sobreposto

 private void Button1_Click(object sender, EventArgs e)
    {

        frmlancar lancar_serv = new frmlancar();

        // Define quem o pai desta janela
        lancar_serv.MdiParent = this;

        // exibe o formulário
        lancar_serv.Show();



    }

1 answer

1

You could use the ShowDialog instead of Show. ShowDialog locks focus to invoked window:

private void Button1_Click(object sender, EventArgs e)
{
    frmlancar lancar_serv = new frmlancar();

    // Define quem o pai desta janela
    lancar_serv.MdiParent = this;

    // exibe o formulário
    lancar_serv.ShowDialog();
}

If it still doesn’t work, put the property lancar_serv.TopMost = true; before the line of ShowDialog.

Browser other questions tagged

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