當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET WindowsFormsApplicationBase.OpenForms屬性代碼示例

本文整理匯總了VB.NET中Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OpenForms屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET WindowsFormsApplicationBase.OpenForms屬性的具體用法?VB.NET WindowsFormsApplicationBase.OpenForms怎麽用?VB.NET WindowsFormsApplicationBase.OpenForms使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase的用法示例。


在下文中一共展示了WindowsFormsApplicationBase.OpenForms屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: GetOpenFormTitles

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
開發者ID:VB.NET開發者,項目名稱:Microsoft.VisualBasic.ApplicationServices,代碼行數:16,代碼來源:WindowsFormsApplicationBase.OpenForms

示例2: GetOpenFormTitles

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
開發者ID:VB.NET開發者,項目名稱:Microsoft.VisualBasic.ApplicationServices,代碼行數:37,代碼來源:WindowsFormsApplicationBase.OpenForms


注:本文中的Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OpenForms屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。