Nov 12, 2011

C# – Check if Form is already running

Here’s a boolean method that checks whether a form is open or not :
1
2
3
4
5
6
7
8
private bool CheckForm(Form form)
{
   foreach (Form f in Application.OpenForms)
       if (form == f)
          return true;
 return false;
}
Example use:
1
2
3
4
5
6
// if form2 is not running
if (!CheckForm(form2))
  {
      // do something
  }

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib