Solved

c# child mdi does not maximize with parent

Posted on 2014-11-05
9
1,973 Views
Last Modified: 2014-11-07
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.
0
Comment
Question by:Lensolo
  • 5
  • 3
9 Comments
 
LVL 5

Expert Comment

by:SerjTech
ID: 40425217
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
 

Author Comment

by:Lensolo
ID: 40426043
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
 

Author Comment

by:Lensolo
ID: 40426048
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40427455
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
 

Author Comment

by:Lensolo
ID: 40428236
Oh. Thanks! That's what I get for googling a solution. I'll try that.
0
 

Author Comment

by:Lensolo
ID: 40428282
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40428692
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
 

Author Comment

by:Lensolo
ID: 40428707
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40428787
"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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question