C# - Form track Panel size

Asked

Viewed 266 times

-1

Hi, I would like to know how I make the open form inside a Panel to follow the Panel if I resize the main form.

        Form2 frm = new Form2();
        frm.TopLevel = false;
        frm.Size = panel1.Size;
        panel1.Controls.Add(frm);
        frm.Show();

I am using the code above to open Form2 inside the Form1 panel and when resizing Frm1 the Form2 continue n the same size.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • 1

    puts the form2 to open maximized

  • Form2 is about to open maximized, the problem is that Form2 is not following the Panel, if I change the size of the Form1 the Panel accompanies due to the Anchor of the Panel, only the Form2 remains static even the Panel accompanying the Form1.

  • remove the edges of the form2, BorderStyle = None... and put to open maximized.. is not, if it were the maximize box would not be appearing but to restore

  • Sorry, I put to maximize and still does not follow.

  • I changed the photos of the post.

  • There is no way to pass the panel size to Form2?

Show 1 more comment

1 answer

0


Define the properties TopLevel, FormBorderStyle and WindowState:

Form2 frm = new Form2();
frm.TopLevel = false;
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm.WindowState = FormWindowState.Maximized;
panel1.Controls.Add(frm);
frm.Show();

By the look of your application, you can open the form inside the main form as well:

Set the property in the main form IsMdiContainer for true, when opening form2, set the main form to "parent":

Form2 frm = new Form2();
frm.WindowState = FormWindowState.Maximized;
frm.MdiParent  = form1; //formulário principal
frm.Show();

If you prefer to keep it with the panel, which I don’t recommend, you can manipulate the Sizechanged event and change the child control by setting the size.

  • Using the Mdiparent option worked perfectly. Thanks for the help.

Browser other questions tagged

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