How, can i get all form name that is created on project using vb.net 2008

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gobi nath
    New Member
    • Oct 2011
    • 16

    How, can i get all form name that is created on project using vb.net 2008

    For Each FRM As Form In Application.Ope nForms
    MsgBox(FRM.Name )
    Next

    only getting open form name... i want all form name used in project
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    You're only getting 1 form because you're using Application.Ope nForms, which gives you the name of the currently open form.

    Take a look at this code and see if it helps:

    Code:
    Public Function GetForms(ByVal sender As Object) As List(Of Form)
    	Dim Forms As New List(Of Form)()
    	Dim formType As Type = Type.GetType("System.Windows.Forms.Form")
    	For Each t As Type In sender.GetType().Assembly.GetTypes()
    	    If UCase(t.BaseType.ToString) = "SYSTEM.WINDOWS.FORMS.FORM" Then
    	    	Forms.Add(t.Name)
    	    End If
    	Next
    	
    	Return Forms
    End Function

    Comment

    • Gobi nath
      New Member
      • Oct 2011
      • 16

      #3
      not working.... it made an error "value of type string cant convert to form"

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        You are right about the error, using this code will get the names of all the forms in your project (sorry for the confusion)

        Code:
        Public Function GetForms(ByVal sender As Object) As List(Of String)
        	Dim Forms As New List(Of String)()
        	
            For Each t As Type In sender.GetType().Assembly.GetTypes()
                If t.BaseType.ToString().ToUpper() = "SYSTEM.WINDOWS.FORMS.FORM" Then
                    Forms.Add(t.Name)
                End If
            Next 
        Return Forms
        End Function
        Last edited by PsychoCoder; Feb 27 '12, 10:11 PM. Reason: Editing code

        Comment

        • Gobi nath
          New Member
          • Oct 2011
          • 16

          #5
          Again error

          Error 17 Value of type 'System.Collect ions.Generic.Li st(Of String)' cannot be converted to 'System.Collect ions.Generic.Li st(Of System.Windows. Forms.Form)

          Comment

          Working...