Reputation: 14075
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:
Application
give me a list of open windows ?Upvotes: 5
Views: 3361
Reputation: 223247
Use Application.OpenForms property like:
int form2Count = Application.OpenForms.OfType<Form2>().Count();
Upvotes: 9