Is there an easy way in a winforms application to get access to the collection of forms that are open and which ones are on top, order they opened, etc.?
I’d like to make it a static class so I can call it anywhere in my code without having to pass objects around.
Otherwise, I’ll have to make my own “window manager” so to speak.
You can get a collection containing all of the forms that are currently open in your application using the
Application.OpenFormsproperty. This is indeed a static property, so it’s available anywhere.However, I’m not sure that this meets your requirements of indicating the order in which the forms were opened. You’re going to have to keep track of this information yourself.
Note that the collection returned by
OpenFormsalso does not track which thread opened each form. If you want to access members of the form, you should check itsInvokeRequiredproperty first to prevent receiving anInvalidOperationExceptionexception.