Solved

c# child mdi does not maximize with parent

Posted on 2014-11-05
9
2,030 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 12 28
MediaHelp 4 26
transaction in asp.net, sql server 6 43
what is the best portable software where i can test codes written in different languages 1 56
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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