get all forms in project

2 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
    1802 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. DevCraft R3 2016 release webinar banner
Back to Top