Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to control...
Message
 
To
16/04/2003 10:32:51
Larry Santos
Local Data System
Philippines
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00778326
Message ID:
00778443
Views:
18
Larry,

One approach is to use the Singleton design pattern. Here is a link to an article that describes this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/singletondespatt.asp

Here is an example about how to limit your form to only one instance:

1. Make the constructor of your form private.
2. Add a private static variable to your form, that is the type of your form.
3. Add a public static read-only property to your form that is the type of your form.
4. In the get method of this property, if the static variable is null, create a new instance of the form. Then return the static variable.

Instead of a property, you can use a function.
class frmClients
{
#Region " Singleton Pattern "
    static frmClients m_instance;
    static frmClients Instance(Form parent)
    {
        if (m_instance = null)
            m_instance = new frmClients(parent);
        return m_instance
    }
    private frmClients(Form parent)
    {
        ...
    } 
#End Region
}
Then elsewhere in your code to call the form
frmClient.Instance(this).Show;
IMPORTANT: Handle either the Closed or Closing event of frmClients by setting m_instance to null in Closed.


>Hi,
>
>I have mdi form and inside of the mdi form i have menu name "Form1" when i click the menu "Form1" the child form1 will popup as a child..but when i again the menu "Form1" the child form1 will popup again..
>
>how to control the form1 child to activate only once and detect if they are still activated...
>
>TIA
>
>Larry Santos
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform