Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MDI parent size to fit MDI child form

Tags:

c#

winforms

mdi

I want the MDI parent to auto-size the child form so it fits inside without scroll bars. Can someone provide some code?

I have used this to differentiate the size of the parent and the child and add it to the size of the parent so I would get a fit. But it's so manual and takes too long to make.

void MDICentertoScreen(Form z,Size addedsize)
{
        foreach (Form f in this.MdiChildren)
        {
            f.Close();
        }
        z.StartPosition = FormStartPosition.CenterScreen;
        z.MdiParent = this;

        //  this.Size = Size.Add(z.Size, addedsize);
        this.CenterToScreen();
        z.Show();
}
like image 536
Jeo Talavera Avatar asked Dec 03 '22 22:12

Jeo Talavera


1 Answers

Maybe this solve your problem:

form.MdiParent = this;
form.Dock=DockStyle.Fill;                
form.Show();
like image 133
Arash Avatar answered Dec 05 '22 10:12

Arash