Jeo Talavera
Jeo Talavera

Reputation: 537

MDI parent size to fit MDI child form

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();
}

Upvotes: 4

Views: 22555

Answers (3)

Arash
Arash

Reputation: 3051

Maybe this solve your problem:

form.MdiParent = this;
form.Dock=DockStyle.Fill;                
form.Show();

Upvotes: 11

user2710668
user2710668

Reputation: 41

Below is what I have used to solve this problem:

  1. In the constructor of the child form, you add this line of code:

this.Dock = DockStyle.Fill;

  1. In the Form_Load event, you should add this line of code:

this.WindowState = FormWindowState.Maximized;

That is, It solves my problem. Good luck!

Upvotes: 4

Brian Tacker
Brian Tacker

Reputation: 1122

This is what I use:

Form form = new Form();
form.MdiParent = this;
form.Show()
form.WindowState = FormWindowState.Maximized;

Upvotes: 2

Related Questions