Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have mdi parent with whom i have attached many child form now i want here is to open first child form and on submit button of first child form second form should open.here first form should be in maximized state and second should be in normal state.so that i can easily close second child form and perform action on first child form pls help me out
Posted
Comments
OriginalGriff 16-Feb-14 3:37am    
What part is giving you difficulty?
Where are you stuck?
ank170989 16-Feb-14 3:54am    
problem is when i open second child form on click of first child forms submit button second form opens in windows maximized state.here i want normal state to second child form and maximized state to first child form
OriginalGriff 16-Feb-14 3:55am    
So you have opens the first child form OK?
How are you opening the second?
ank170989 16-Feb-14 4:00am    
i am opening second form like this

this.WindowState = FormWindowState.Maximized;
form mesb = new form();

mesb.MdiParent = this.MdiParent;
mesb.WindowState = FormWindowState.Normal;
mesb.Show();
mesb.BringToFront();
OriginalGriff 16-Feb-14 3:56am    
BTW: Use the Reply feature if someone talks to you - it sends them an email, which a comment doesn't.

I'm afraid you can't do that: http://social.msdn.microsoft.com/Forums/windows/en-US/9fa480ba-d0ce-4c70-8a22-dc740d710622/mdi-application-child-forms-maximizenormalminimize-independent?forum=winformsdesigner[^]

MDI children are not independent, you can't have one Maximized and another not, they just don't work like that. The only way you could "fake" it, would be to have a non-MDI second child, and limit its movement to within the parent rectangle.

This is one of the reasons why MDI is discouraged in modern apps: it just wasn't very flexible!
 
Share this answer
 
As OriginalGriff pointed out, you cannot manipulate individual MDI Child Windows with setting 'WindowState. And, I agree with his recommendation that you avoid using MDI. However, many people are still using MDI, and many students are given assignments to create MDI apps.

You can "work around" not being able to use 'WindowState like this:

Assume you have two MDI Child Forms: ChildForm1, ChildForm2

1. on ChildForm1 is a Button, 'button1: in the code for ChildForm1 you have a Public Property of Type Button that you expose:
C#
namespace YourNameSpace
{
    public partial class childForm1 : Form
    {
        public childForm1 ()
        {
            InitializeComponent();
            ChildForm1Button = this.button1;
        }

        public Button ChildForm1Button { private set; get; }
    }
}
In your MDI Parent Form:
C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace YourNameSpace
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private ChildForm1 childForm1 = new ChildForm1();
        private ChildForm2 childForm2 = new ChildForm2();

        private void Form1_Load(object sender, EventArgs e)
        {
            childForm1.MdiParent = this;
            childForm2.MdiParent = this;

            childForm1.ChildForm1Btn.Click += ChildForm1Btn_Click;

            childForm1.Show();
        }

        private void ChildForm1Btn_Click(object sender, EventArgs e)
        {
            Rectangle rect = this.ClientRectangle;
            rect.Inflate(-20, -20);

            childForm2.Bounds = rect;
            childForm2.Show();
            childForm1.BringToFront();
        }
    }
}
Initially, 'childForm1 is shown. When the Button on 'childForm1 is clicked:

1. the client rectangle of the MDI Parent is recorded, and then "shrunk" by 20 pixels: the 'Inflate command will effectively both change the Location and Size of the Rectangle.

2. 'childForm2's Bounds are set to the changed Rectangle, 'rect.

3. 'childForm2 is shown

4. 'childForm1 is brought back to the front of the z-order.

You might consider making your MDI Child Forms have no Minimize, or Maximize, Controls, no Titles, no CloseBox, etc., if you want to have complete control or size, position, and z-order of child Forms. But, that's going to take some work.

Of course, you can take advantage of MDI's build-in facilities to tile child Forms in various ways by calling the this.Layout.Mdi() method in your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900