C# 2005 beta I developd MDI form and I can not limit the number of child form. After opened the form and it can open again and again at the same page. I need to limit number fo the child forn in the parent form.
One way to limit this is to have a static variable that gets incremented each time, you instantiate a new form. In the Form_Closing event of all the forms you would need to decrement the same variable.
Once the variable reaches a particular count, you say the user has exceed maximum number of child forms.
I think what your asking for is a singleton class. You want just one instance of a class to be able to be opened right Here is an example of how to implement a singleton class. Where ever the class is instantiated you would want to call it like this
//create the new screen Landing LandingScreen = Landing.Instance();
//Display Screen LandingScreen.Show();
now in the constructor region of the class that you are instantiating add code that looks like this
How to limit number of child form in parent form.
Bryce Covert
One way to limit this is to have a static variable that gets incremented each time, you instantiate a new form. In the Form_Closing event of all the forms you would need to decrement the same variable.
Once the variable reaches a particular count, you say the user has exceed maximum number of child forms.
Regards,
Vikram
NarasimhaMurthy
//create the new screen
Landing LandingScreen = Landing.Instance();
//Display Screen
LandingScreen.Show();
now in the constructor region of the class that you are instantiating add code that looks like this
private static Landing aLanding = null;
public static Landing Instance()
{
if(aLanding==null)
{
aLanding= new Landing();
}
else
{
}
return aLanding;
}
private Landing() // note that this has changed to from public to private
{
InitializeComponent();
}
And that's it now the form may only be opened once!