How to count all open forms of 1 specific class?
c#, winapi, windows, winforms
Solution
Use Application.OpenForms property like:
int form2Count = Application.OpenForms.OfType<Form2>().Count();
Problem
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). - Form1 (main) - Form2 (can be many) - Form3 (other forms) The app can't be started multiple times. So it's just about counting the windows in this one application. My ideas: - Can `Application` give me a list of open windows ? - WinApi, enumerate windows of 1 application ? - put every new Form2 window into a list (I wish to avoid that)