c# child mdi does not maximize with parent

I have a MDI form with a child form docked that works great until I maximize the window. When I do, the child form does not maximize to fill up the MDI Parent. I have been trying to catch & resize the object on Parent Resize, but I'm just not having luck.

Also, the child's Window state is set to maximize and autosize is set to True (I have tried it both ways). I have also set the parent form ISMDIContainer to True.

My code to load the client from a menu item click on the parent MDI form is:
            frmChild newCurt = new frmChild();
            newCurt.TopLevel = false;
            newCurt.AutoScroll = true;
            newCurt.FormBorderStyle = FormBorderStyle.None;
            this.Controls.Add(newCurt);
            newCurt.Show();

I am building this in VS2012 / c# .net 4.5.
LensoloAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SerjTechCommented:
When you create the child is it set to FormWindowState.Normal; ?

Then when the parent is maximized set the child's window state, in the code, to maximized.

Does this work?

If not let me know and will try and build a quick demo to test it.
0
LensoloAuthor Commented:
I don't see a way to set the child WindowState when the parent resizes. This is the only way I know to set the child properties after iot has been added to the parent controls.

 MdiClient client = null;
            foreach (Control contr in this.Controls)
            {
              if (contr.GetType() == typeof(MdiClient))
            {
                client = (MdiClient)contr;
                client.Size = new Size(this.Width,this.Height);
             }
            }
0
LensoloAuthor Commented:
If you can create 2 new forms & get them to resize with eachother, I just need to know what settings makes this work. I am spending too much time on this and getting no results. I'm really surprised this is not doing it as expected.

Also, the suggestion you mention above does not work with the code I published.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You are not really using MDI Forms in the proper manner.  Your child form is not really an MDI child, and your main form does not need IsMdiContainer() set to true.

To "fix" your problem, simply set Dock to Fill for the child form:
newCurt.Dock = DockStyle.Fill;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LensoloAuthor Commented:
Oh. Thanks! That's what I get for googling a solution. I'll try that.
0
LensoloAuthor Commented:
That didn't fix the issue, but I dug up some code on Microsoft and I see why you said I wasn't using it correctly. I had to just set the parent of the MDI child. The following code works. I'm posting in case someone else find the same 10 or so links I found from Googling this that work, but aren't the right way to code this. Thanks for pointing that out.

            this.IsMdiContainer = true;
            fMDIChildTest newMDIChild = new fMDIChildTest();
            newMDIChild.MdiParent = this;
            newMDIChild.WindowState = FormWindowState.Maximized;
            newMDIChild.FormBorderStyle = FormBorderStyle.None;
            newMDIChild.Show();

This is from: http://msdn.microsoft.com/en-us/library/aa984329(v=vs.71).aspx
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
An MDI setup with no Form Border also don't seem to go together in my mind.  The whole point of MDI is that you can move the windows around inside the parent client area.  Not sure what your app looks like, or how it behaves, so I could be wrong.  Good luck!
0
LensoloAuthor Commented:
I just wanted to contain most of the screens to a designated location on my parent form & fill the form. A menu strip will switch out the screens. Some screens will become popup screens, but very specific ones & I will handle these differently. Anyway, thank you.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
"I just wanted to contain most of the screens to a designated location on my parent form & fill the form."

You can do that using your original approach setting TopLevel to false and adding the form to a SPECIFIC container.  For instance, you can add a Panel to your form, then add the Form to that Panel in code.  With Dock set to Fill on the Form, it will resize when the Panel resizes.  Just make sure your Panel is setup correctly to resize when the main form resizes.

So instead of:

    this.Controls.Add(newCurt);

You'd have something like:

    panel1.Controls.Add(newCurt);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.