To check if a form is already running you’ll have to look for it in the Application.OpenForms collection. When a form is opened it is added to that collection.
Here’s a boolean method that checks whether a form is open or not :
private bool CheckForm(Form form)
{
foreach (Form f in Application.OpenForms)
if (form == f)
return true;
return false;
}
Example use:
// if form2 is not running
if (!CheckForm(form2))
{
// do something
}
Thanks.
If you have any questions, don’t hesitate to post a comment.