0
votes

I have a Windows Forms application that opens MDI child forms. When I select those forms, I need to set or render its windowstate to Maximized. The problem is, when I navigate between the open forms, it reverts back to the normal window state, and when I set the window state to maximized again, it shows the transition from normal to maximized state and it doesn't look nice.

How can a Windows application be created that have an MDI parent form that opens many MDI childs in maximized window state?

4
Yes, that's clear, but let me ask you : are you willing to use an alternative to MDI, and "give up" whatever other "features" of MDI you are now using ? I think it would also be valuable if you would say exactly how you (or the run-time end-user) "navigate between the open forms" : via menu on the MDI Parent form ? Or ... ?BillW
yes. in the parent, there is a menu that select its child. what alternative i can use? is it tabcontrol?Jepe d Hepe
So, no problem for you in "giving up" the MDI "feature" where, when you minimize a "child" form (MDIParent property of the form set to the MDIParent Form), it goes down to the bottom of the parent MDI form with the TitleBar visible ? Are you using the "automatic Window menu feature" of MDI as described at : msdn.microsoft.com/en-us/library/ms171654(VS.100).aspx ? No problem giving that up if you leave MDI behind ?BillW

4 Answers

3
votes

If you want the window state to always be maximized, I'd recommend switching away from an MDI Form. A TabControl may work better, in that case.

MDI forms have quite a few usability issues, which is why they are not commonly used anymore, and tend to be replaced with other controls/options.

3
votes

Here's an answer based on using the MDI "Parent Form and Child Form paradigm," with the following assumptions :

  1. you have a MenuStrip control 'Dock = 'Top on your MDIParentForm, and you've implemented the automatic MDI &Window menu handler as described in : How to: Create an MDI Window List with MenuStrip

  2. you are creating new child forms that :

    a. do not have a MaximizeBox, MinimizeBox, etc., but may have ControlBox (for closing them)

    b. these child forms may be resizable or not : we won't consider the implications of that here.

  3. You want these MDIChildForms to display maximized in the MDIParent Form, but not to obscure the MDIParentForm's menu.

Okay : assuming you have all your child Forms fully designed, "waiting in the wings" : we might see some code like this in your MDIParentForm code :

    // create instances of your child forms
    Form2 f2 = new Form2();
    Form3 f3 = new Form3();
    Form4 f4 = new Form4();
    Form5 f5 = new Form5();

    private void MDIParentForm1_Load(object sender, EventArgs e)
    {
        f2.Text = "subForm1";
        f3.Text = "subForm2";
        f4.Text = "subForm3";
        f5.Text = "subForm4";

        f2.MdiParent = this;
        f3.MdiParent = this;
        f4.MdiParent = this;
        f5.MdiParent = this;

        f2.Dock = DockStyle.Fill;
        f3.Dock = DockStyle.Fill;
        f4.Dock = DockStyle.Fill;
        f5.Dock = DockStyle.Fill;

        f2.Show();
        f3.Show();
        f4.Show();
        f5.Show();
    }

At this point, the dock style 'Fill applied to the child forms will make them full-screen, and keep them from obscuring the MDIParentForm menu : and the menu will allow you to auto-select which one is frontmost.

Now, if you want to do fancier stuff : like resizing the child Forms, tiling them, cascading them. You are going to have to change the 'Dock property of these child windows : and then you can make use of the built-in MDI paradigm window arranging facilities as described here : How to: Arrange MDI Child Forms

And if you want to create multiple instances of one type of pre-defined child form : How to Create MDI Child Forms ... see the example on how to use a 'New menu entry : may prove useful.

0
votes

After reading Reeds answer and especially your comment:

problem with tabcontrol is, i have a lot of controls used per child form

Maybe this will help: Don't put your controls into a Winform. Instead encapsulate them into a UserControl (maybe it already works by changing your inheritance from Form to UserControl).

Now put every UserControl on it's own TabPage and set its Dock property to Fill. Now you are able to change each UserControl on it's own, without any interference to another control on another TabPage (as far as you don't built in any connection).

0
votes

If you intend to give up on MDI, you could have a look at docking frameworks like WeifenLuo or DigitalRune. These are free, for other options you can have a look here: http://windowsclient.net/downloads/folders/controlgallery/tags/Windows+Forms+Docking+Windows/default.aspx


EDIT:

If I remember well, DigitalRune allows the usage of windows forms as containers for docked content so the migration effort would be smaller.