Single reusable function to open a single instance of form
<p>I am trying to create a reusable function that can open a single instance of form. Means if a form is not already open it should create and show the new form and if already open it should bring the existing form to front.</p>

<p>I was using the following function,</p>

<pre><code>if (Application.OpenForms["FPSStorageDemo"] == null)
            {
                FPSStorageDemo fp = new FPSStorageDemo();
                fp.Name = "FPSStorageDemo";
                fp.Show();
            }
            else
            {
                ((FPSStorageDemo)Application.OpenForms["FPSStorageDemo"]).BringToFront();
            }
</code></pre>

<p>But I have to write this code again and again whereever I have to open a form. But I need a single reusable function that can do this job.</p>

<p>I wrote a function like,</p>

<pre><code>void OpenSingleInstanceForm(Type TypeOfControlToOpen)
        {
            bool IsFormOpen = false;
            foreach (Form fm in Application.OpenForms)
            {
                if (fm.GetType() == TypeOfControlToOpen)
                {
                    IsFormOpen = true;
                    fm.BringToFront();
                    break;
                }
            }

            if (!IsFormOpen)
            {
                Object obj = Activator.CreateInstance(TypeOfControlToOpen);
                //obj.Show(); //Here is the problem
            }
        }
</code></pre>

<p>But at the end I don't know how to show the new form instance. Can anybody suggest how to do it? Is this wrong or there is another way to do this?</p>

<p>Thanks in advance.</p>
