get all forms in project

4 posts, 0 answers
  1. ali
    ali avatar
    3 posts
    Member since:
    Sep 2011

    Posted 13 Apr 2012 Link to this post


    i used to have a code in vb that used to retrieve all the forms in my project and add them to a group box, here it is: 

    Dim formType As Type
           'An assembly in .NET is an executable file (.EXE or .DLL)
           'GetType returns the type object for the specified typename
           For Each formType In sender.GetType().Assembly.GetTypes()
               'Select only the application forms inherited from the generalfunctionsform and add them to formList
               If UCase(formType.BaseType.ToString).Contains("SYSTEM.WINDOWS.FORMS.FORM") Then
                   formList.Add(CType(Activator.CreateInstance(formType), Form))
               End If
           'Convert each form reference to a name string and add an entry to the formNames list
           For Each form As Form In formList

    but now that im using radForms, it doesnt seem to be able to return them to me as it loops throught the types in the projects. Anything i can do to get a ll the radForms in my project?

    Thank you in advance
  2. Nikolay
    Nikolay avatar
    1805 posts

    Posted 17 Apr 2012 Link to this post

    Hi Ali,

    Thank you for writing.

    You can get the RadForm descendants that you have in your project by following this approach:

    Public Class MainForm
        Private formTypes As New List(Of Type)()
        Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
            For Each formType As Type In System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
                If GetType(RadForm).IsAssignableFrom(formType) Then
                    If formType.FullName <> "FormsTypes.MainForm" Then
                    End If
                End If
            Next formType
            For Each type As Type In formTypes
            Next type
        End Sub
    End Class

    I am attaching a sample project which demonstrates what this code snippet produces as a result.

    I hope this helps.

    All the best,
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Sushant
    Sushant avatar
    1 posts
    Member since:
    May 2019

    Posted 08 May 2019 in reply to Nikolay Link to this post

    Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

            Dim types As Type() = myAssembly.GetTypes()
            For Each t As Type In types
                If UCase(t.BaseType.ToString) = "SYSTEM.WINDOWS.FORMS.FORM" Then
                    If t.BaseType.Name = "Form" Then
                        'MessageBox.Show((CType(Activator.CreateInstance(t), Form).Text))
                        MessageBox.Show("  " & t.Name & vbCrLf & " Name is : " & (CType(Activator.CreateInstance(t), Form).Text))
                    End If
                End If

  4. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4169 posts

    Posted 08 May 2019 Link to this post

    Hello, Sushant,     

    Thank you for sharing your solution with the community.

    You can find useful as well the following threads:

    I hope this information helps. 

    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top