Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have created application that have MDIParent form and other no of forms.
Mdiparent allowing to open multiple forms. That should not be allowed so should do.
I have sample code for form below.

C#
private void employeeEntryToolStripMenuItem_Click(object sender, EventArgs e)
       {
           frmEmployeeEntry EmpEntry = new frmEmployeeEntry();
           EmpEntry.MdiParent = this;
           EmpEntry.Show();
       }







What's wrong in it.
Suggest right code pls.
Thanks in advamce.
Posted
Comments
Sergey Alexandrovich Kryukov 6-Sep-12 1:56am    
Why using MDI if you don't want to allow multiple children? Why using MDI at all? Who needs it, ever?
And what is the problem with your code? Is "this" a MDI container?
--SA
SamWakchaure 6-Sep-12 2:05am    
its MDI Parent form.

hi...

before opening a child form, u should check whether any mdichildren forms are open, and if yes, close them, like below:
C#
foreach(Form frmChild in this.MdiChildren)
{
frmChild.Close();
}


After this, u can open new form.
 
Share this answer
 
v2
put new child form opening code inside this condition
C#
if (MDI.MdiChildren.Length >0)
{
 //message please close form already open
}
else
{
 //open form
}


else simple way,
use ShowDialog note: it will not allow to access MDI form till this form is closed.
C#
frmEmployeeEntry EmpEntry = new frmEmployeeEntry();
EmpEntry.ShowDialog()

Happy Coding!
:)
 
Share this answer
 
v2

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