Export (0) Print
Expand All

WindowsFormsApplicationBase.OpenForms Property

Note: This property is new in the .NET Framework version 2.0.

Gets a collection of all the application's open forms.

Namespace: Microsoft.VisualBasic.ApplicationServices
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public FormCollection OpenForms { get; }
/** @property */
public FormCollection get_OpenForms ()

public function get OpenForms () : FormCollection

Property Value

A FormCollection object that contains all of the application's open forms.

For more detailed information, see the Visual Basic topic My.Application.OpenForms Property.

The My.Application.OpenForms property gets a collection of all the application's open forms. The behavior is identical to the Application.OpenForms property.

NoteNote

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.

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

How to: Access All Open Forms of an Application

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.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft