9.4. Track the Visible Forms in an Application

Problem

You need access to all the open forms that are currently owned by an application.

Solution

Iterate through the FormCollection object that you get from the Shared property OpenForms of the Application object.

How It Works

Since .NET Framework 2.0, Windows Forms applications automatically keep track of the open forms that they own. This information is accessed through the Application.OpenForms property, which returns a FormCollection object containing a Form object for each form the application owns. You can iterate through the FormCollection to access all Form objects or obtain a single Form object using its name (Form.Name) or its position in the FormCollection as an index.

The My object ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.