VM,
I would have a factory method/property that would handle this for you,
something like this:
// Stores the instance of the current form.
private static Form form;
public static Form GetForm()
{
// If the form is null, create it here.
if (form == null)
{
// Create it here.
form = new Form();
// Handle the closed event, when closed, set the form to null.
// This syntax is for .NET 2.0. You can just create a delegate and
add that
// to the form for previous versions.
form.Closed += delegate
{
// Set form to null.
form = null;
};
}
// Return the form.
return form;
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
// Declare constructor private. This probably will give you designer
problems though, so
// you don't have to do this.
"VM" <vi***********@gmail.com> wrote in message
news:uA**************@TK2MSFTNGP14.phx.gbl...
Hi,
Is it possible to open always only one instance of a MDIChild form?
Say, if form A is already opened, just give it the focus.
I tried declaring theMDIChild forms as private members of the MDI form
(using the MDI menu's script), but when the MDIChild form is closed (x
button pushed), I cannot open again the MDIChild form.
Example:
// aForm is a private member of the MDI form.
if (aForm.Visible)
aForm.Activate();
else
aForm.Show();
// This works nice once, and the form gets the focus once it's already
opened, but if it's closed *once* it doesn't open again.