Click here to Skip to main content
14,362,827 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have developed a Windows Desktop Application with a MDI Container form which will open first. This MDI form houses many child forms as part of its Menu. On the click event of this menu items I have written the following code.

Masters.frmCustomer objCUST = new Masters.frmCustomer();
//objCUST.MdiParent = this;
objCUST.Show();

My problem is when I am executing the application with the second statement commented, the child form opens perfectly OK (in its own original shape). Bust as I un-comment the second statement the child form appears fully stretched inside the parent window - dis-forming the form structure. So please suggest me a solution where I can maintain the proper structure of the opening child forms inside the MDI window.

I am using VC# 2010.

Thanks,

IB
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Change the child forms WindowState to FormWindowState.Normal
   
Comments
Indrojeet_Bhattacharya 20-Sep-14 10:26am
   
hi OriginalGriff,

I tried your solution but could not get the required results. The child form is still appearing as spread out. Please suggest.
OriginalGriff 20-Sep-14 10:53am
   
And where did you do it?
Indrojeet_Bhattacharya 21-Sep-14 5:35am
   
I wrote this code in the click event of the menu item inside the mdi form .cs file.
OriginalGriff 21-Sep-14 6:02am
   
Move it to the Child form Shown event
Indrojeet_Bhattacharya 21-Sep-14 6:56am
   
I have modified the code as:
private void customersMenuItem1_Click(object sender, EventArgs e)
{

Masters.frmCustomer objCUST = new Masters.frmCustomer();
objCUST.Show(this);
}

in MDI form and

private void frmCustomer_Shown(object sender, EventArgs e)
{
frmMAIN obj1 = new frmMAIN();
MdiParent = obj1;
WindowState = FormWindowState.Normal;
}

in Child form shown event

Now the child form is opening and then immediately closing.
OriginalGriff 21-Sep-14 7:13am
   
Why, pray, are you creating a brand new instance of your main MDI form, and assigning that as the MDI parent? You know that is never going to work, and will close the MDI Child since it's parents' window will be NULL - the new instance has never been Shown so it doesn't have a window yet...
Indrojeet_Bhattacharya 21-Sep-14 7:31am
   
please suggest me the code then.
OriginalGriff 21-Sep-14 7:38am
   
What code? Just rip out the frmMAIN stuff!
Indrojeet_Bhattacharya 21-Sep-14 8:09am
   
Now there is a strange observation: created a new MDI form with exactly the same menu definition and settings and ho!! the child forms are behaving in a disciplined decent way. Totally amazed ... do you have any idea ?
OriginalGriff 21-Sep-14 8:11am
   
When you open any MDI child, it will appear in the same way as the last one opened - so if you have set a Maximised form in your parent before, any new form will also be maximised.
Probably, your new form if just following a non-maximised MDI child, so it works fine.
Indrojeet_Bhattacharya 21-Sep-14 8:31am
   
thanks for the input but in the new form also i used the start position=maximized. Just now found something which I would like to share with you and you will not believe it. In my "troubled" mdi form I was using Font="Verdana, 11pt", moment I changed it back to "Microsoft Sans Serif, 8.25pt" everything started working fine. A new learning in process. But anyways thank you very much for your contentious helpful inputs and of-course keeping patience with me. Thanks again.
Rate this:
Please Sign up or sign in to vote.

Solution 2

In addition to doing what OriginalGriff advised you to do: check to see there's anything in 'frmCustomer's Load or Shown Events (if they are defined) that is setting any aspect of the Form visual state, like WindowState, StartUpPosition, etc. Comment out that code if it is present.

Try setting 'frmCustomer's StartPosition to 'WindowsDefaultLocation, or 'Manual, to see if that has any effect.

What you describe should definitely not be happening, if you are using standard Windows Forms and adding them in code in the standard way to an Mdi Container, then setting their MdiParent to the Mdi Container Form.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

In my "troubled" mdi form I was using Font="Verdana, 11pt", moment I changed it back to "Microsoft Sans Serif, 8.25pt" everything started working fine.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100