You should create a singleton class for managing your form instances:
public class FormProvider
{
public static UserForm UserForm
{
get
{
if (_userForm== null || _userForm.IsDisposed)
{
_userForm= new UserForm ();
}
return _userForm;
}
}
private static UserForm _userForm;
}
NB, this is a very simple Singleton pattern. For the correct way to use the pattern, use this link.
You can then just access the form as follows:
FormProvider.UserForm.Show();
FormProvider.UserForm.MdiParent = this;
When FormProvider.UserForm
is accessed for the FIRST time, it will be created. Any subsequent get on the FormProvider.UserForm
property will return the form that was created on first access. This means that the form will only ever be created once.