My.Application.OpenForms Property
Gets a collection of all the application's open forms.
' Usage
Dim value As System.Windows.Forms.FormCollection = My.Application.OpenForms
' Declaration
Public ReadOnly Property OpenForms As System.Windows.Forms.FormCollection
Return Value
A FormCollection object that contains all of the application's open forms.
Remarks
The My.Application.OpenForms property gets a collection of all the application's open forms. The behavior is identical to the System.Windows.Forms.Application.OpenForms property.
Note
The My.Application.OpenForms property returns all open forms, regardless of which thread opened them. You should check the InvokeRequired property of each form before accessing it; otherwise, it might throw an InvalidOperationException exception. For more information, see How to: Access All Open Forms of an Application.
Tasks
The following table lists examples of tasks involving the My.Application.OpenForms property.
To | See |
---|---|
Display the titles of all the application's open forms |
Example
This example loops over the application's open forms, selects the ones directly accessible by the current thread, and displays their titles in a ListBox control. To access the open forms, see How to: Access All Open Forms of an Application.
Private Sub GetOpenFormTitles()
Dim formTitles As New Collection
Try
For Each f As Form In My.Application.OpenForms
If Not f.InvokeRequired Then
' Can access the form directly.
formTitles.Add(f.Text)
End If
Next
Catch ex As Exception
formTitles.Add("Error: " & ex.Message)
End Try
Form1.ListBox1.DataSource = formTitles
End Sub
This example requires that your Windows Forms application have a form named Form1
that contains a list box named ListBox1
.
Requirements
Namespace: Microsoft.VisualBasic.ApplicationServices
Class: WindowsFormsApplicationBase
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Project type | Available |
---|---|
Windows Application |
Yes |
Class Library |
No |
Console Application |
No |
Windows Control Library |
No |
Web Control Library |
No |
Windows Service |
No |
Web Site |
No |
Permissions
The following permission may be necessary:
Permission | Description |
---|---|
Controls the permissions related to user interfaces and the clipboard. Associated enumeration: AllWindows. |
For more information, see Code Access Security and Requesting Permissions.
See Also
Reference
My.Application Object
System.Windows.Forms.FormCollection
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OpenForms
System.Windows.Forms.Application.OpenForms