WindowsFormsApplicationBase.OpenForms 속성

정의

애플리케이션의 열려 있는 모든 폼 컬렉션을 가져옵니다.

public:
 property System::Windows::Forms::FormCollection ^ OpenForms { System::Windows::Forms::FormCollection ^ get(); };
public System.Windows.Forms.FormCollection OpenForms { get; }
member this.OpenForms : System.Windows.Forms.FormCollection
Public ReadOnly Property OpenForms As FormCollection

속성 값

애플리케이션의 열려 있는 양식을 모두 포함하는 컬렉션입니다.

예제

이 예제에서는 애플리케이션의 열려 있는 폼 반복 현재 스레드에서 사용 하 여 직접 액세스할 수 있는 선택 하 고에 해당 제목이 표시는 ListBox 제어 합니다. 이 예제는 Windows Forms 애플리케이션 이라는 폼 Form1 명명 된 목록 상자를 포함 하는 ListBox1합니다.

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

이 예제에서는 애플리케이션의 열려 있는 폼을 반복 하 고에 해당 제목이 표시는 ListBox 제어 합니다.

Private Sub GetOpenFormTitles()
    Dim formTitles As New Collection

    Try
        For Each f As Form In My.Application.OpenForms
            ' Use a thread-safe method to get all form titles.
            formTitles.Add(GetFormTitle(f))
        Next
    Catch ex As Exception
        formTitles.Add("Error: " & ex.Message)
    End Try

    Form1.ListBox1.DataSource = formTitles
End Sub

Private Delegate Function GetFormTitleDelegate(f As Form) As String
Private Function GetFormTitle(f As Form) As String
    ' Check if the form can be accessed from the current thread.
    If Not f.InvokeRequired Then
        ' Access the form directly.
        Return f.Text
    Else
        ' Marshal to the thread that owns the form. 
        Dim del As GetFormTitleDelegate = AddressOf GetFormTitle
        Dim param As Object() = {f}
        Dim result As System.IAsyncResult = f.BeginInvoke(del, param)
        ' Give the form's thread a chance process function.
        System.Threading.Thread.Sleep(10)
        ' Check the result.
        If result.IsCompleted Then
            ' Get the function's return value.
            Return "Different thread: " & f.EndInvoke(result).ToString
        Else
            Return "Unresponsive thread"
        End If
    End If
End Function

설명

My.Application.OpenForms 속성 애플리케이션의 모든 열려 있는 폼의 컬렉션을 가져옵니다. 동작은 속성과 Application.OpenForms 동일합니다.

참고

My.Application.OpenForms 속성을 열 스레드에 관계 없이 열려 있는 모든 폼을 반환 합니다. 액세스하기 전에 각 양식의 속성을 검사 InvokeRequired 합니다. 그렇지 않으면 예외가 InvalidOperationException 발생할 수 있습니다.

프로젝트 형식에 따라 가용성

프로젝트 형식 사용 가능
Windows Forms 애플리케이션
클래스 라이브러리 No
콘솔 애플리케이션 No
Windows Forms 컨트롤 라이브러리 No
웹 컨트롤 라이브러리 No
Windows 서비스 No
웹 사이트 No

적용 대상

추가 정보