Click here to Skip to main content
15,898,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Change the child forms WindowState to FormWindowState.Normal
 
Share this answer
 
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.
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.
 
Share this answer
 
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
 
Share this answer
 
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.
 
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