Tuesday, 16 March 2010

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;
}

No comments:

Post a Comment