Thursday, May 10, 2012

Allow only one instance of any Windows Form, C#

The ability to load forms once, is something essential in many applications. But, this is a simple way to do that:

public Boolean IsFormAlreadyLoaded(string formToLoadName)
{
    //Allow only one instance of any MDI child form in your MDI application
    
foreach (Form frmChild in this.MdiChildren)
    {
        if (frmChild.Name == formToLoadName)
        {
            frmChild.Activate();
            
return true;
        }
    }
    
return false
}



ref: http://yourprosoft.blogspot.com/2010/03/allow-only-one-instance-of-any-windows.html

No comments:

Post a Comment