Bitterblue
Bitterblue

Reputation: 14075

How to count all open forms of 1 specific class?

I have a few Form-classes that derive from Form. And I want to count all open form instances of 1 special class like Form2. It's a simple WinForms application (no Mdi).

The app can't be started multiple times. So it's just about counting the windows in this one application.

My ideas:

Upvotes: 5

Views: 3361

Answers (1)

Habib
Habib

Reputation: 223247

Use Application.OpenForms property like:

int form2Count = Application.OpenForms.OfType<Form2>().Count();

Upvotes: 9

Related Questions