views:

451

answers:

4

I have a Winform that opens mdichild forms. When i select those forms, i need to set or render its windowstate to Maximized. Problem is, when i navigate between the open forms, it reverts back to normal windowstate. and when i set the windowstate to maximized again, it shows the transition from normal to maximized state and it doesn't look nice.

Can you help me out or give me some advise on creating windows application that have a mdiparent form that opens many mdichild in maximized windowstate.

+3  A: 

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.

Reed Copsey
problem with tabcontrol is, i have a lot of controls used per child form.
Jepe d Hepe
And that is a problem because...? You can put these into a UserControl, and host each UserControl in a tab. You can even create them on-demand, when the tab is displayed, and it will have the same (or lower) overhead than an MDI form.
Reed Copsey
+2  A: 

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.

BillW
A: 

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).

Oliver
Forms can also be used in TabPages with no problems (you'll probably want to turn off unneeded Form visual elements) : but, since UserControls are "lighter weight," perhaps that's the best way to do it. Once a UserControl (or Form) is added to a TabPage's Controls collection, you can access only toplevel properties : if you change the "source" UserControl or Form : you'll need to re-build the project (not a big deal). It's a habit of mine to fill the TabPages (if they're only used to hold a UserControl) in code in the Form Load event of the "main form," but that's just personal preference.
BillW
A: 

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.

Sorin Comanescu