none
How to list all forms in a project?

Answers

  • Here you go

    Imports System.Reflection
    
    Public Class ProjectForms
        Public Property FormNames As List(Of String)
        Public Sub New()
            FormNames = New List(Of String)
            GetFormNames()
        End Sub
        Private Sub GetFormNames()
            Dim formType As Type = GetType(Form)
            For Each type As Type In Reflection.Assembly.GetExecutingAssembly().GetTypes()
                If formType.IsAssignableFrom(type) Then
                    FormNames.Add(type.Name)
                End If
            Next
        End Sub
        Public Function CreateObjectInstance(ByVal objectName As String) As Object
            Dim obj As Object
            Try
                If objectName.LastIndexOf(".") = -1 Then
                    objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName
                End If
    
                obj = [Assembly].GetEntryAssembly.CreateInstance(objectName)
    
            Catch ex As Exception
                obj = Nothing
            End Try
            Return obj
    
        End Function
    End Class
    


    Public Class Form1
        Private ops As New ProjectForms
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim frm As New Form
            frm = DirectCast(ops.CreateObjectInstance(ListBox1.Text), Form)
            frm.Show()
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListBox1.DataSource = ops.FormNames
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by kingelk Tuesday, March 28, 2017 9:47 AM
    Saturday, March 25, 2017 1:00 PM
    Moderator

All replies

  • Here you go

    Imports System.Reflection
    
    Public Class ProjectForms
        Public Property FormNames As List(Of String)
        Public Sub New()
            FormNames = New List(Of String)
            GetFormNames()
        End Sub
        Private Sub GetFormNames()
            Dim formType As Type = GetType(Form)
            For Each type As Type In Reflection.Assembly.GetExecutingAssembly().GetTypes()
                If formType.IsAssignableFrom(type) Then
                    FormNames.Add(type.Name)
                End If
            Next
        End Sub
        Public Function CreateObjectInstance(ByVal objectName As String) As Object
            Dim obj As Object
            Try
                If objectName.LastIndexOf(".") = -1 Then
                    objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName
                End If
    
                obj = [Assembly].GetEntryAssembly.CreateInstance(objectName)
    
            Catch ex As Exception
                obj = Nothing
            End Try
            Return obj
    
        End Function
    End Class
    


    Public Class Form1
        Private ops As New ProjectForms
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim frm As New Form
            frm = DirectCast(ops.CreateObjectInstance(ListBox1.Text), Form)
            frm.Show()
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListBox1.DataSource = ops.FormNames
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by kingelk Tuesday, March 28, 2017 9:47 AM
    Saturday, March 25, 2017 1:00 PM
    Moderator
  • Just checking to see if this issue has been resolved or not.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, March 27, 2017 9:42 AM
    Moderator
  • Thank you Karen. You are always most helpful! much appreciated! :)


    Tuesday, March 28, 2017 9:52 AM
  • Thank you Karen. You are always most helpful! much appreciated! :)


    Your very welcome.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, March 28, 2017 10:17 AM
    Moderator