Data-Base Data-Base - 1 year ago 138
C# Question

How to check if a windows form is already open, and close it if it is?

I have a form "fm" that is a simple info window that opens every 10 mins (


How I can make that every 10 mins it will check if the form "fm" is open and if it is open it closes it and open it again!

Now the form fm is always created with
form fm = new form();

so when I try to check if the form is open it will always be false and open a new window even if there is one form before!

I need to have a tool to give it a unique identity and then check if this form with unique identity is opened or not!

I do not want to just update the data on the form (fm), because I have a complicated info with buttons.

The form name is

Solved with with the following:

Form fc = Application.OpenForms["UpdateWindow"];

if (fc != null)


Answer Source

maybe this helps:

FormCollection fc = Application.OpenForms;

foreach (Form frm in fc)
//iterate through

Some code in the foreach to detect the specific form and it could be done. Untested though.

Found on

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download