This is a migrated thread and some comments may be shown as answers.

get all forms in project

3 Answers 547 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ali
Top achievements
Rank 1
ali asked on 13 Apr 2012, 04:13 PM
Hello,

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
               MsgBox(formType.BaseType.ToString)
               formList.Add(CType(Activator.CreateInstance(formType), Form))
           End If
       Next
 
       'Convert each form reference to a name string and add an entry to the formNames list
       For Each form As Form In formList
           formsListBox.Items.Add(form.Name.ToString)
       Next

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

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 17 Apr 2012, 03:45 PM
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
                    MessageBox.Show(formType.ToString())
                    formTypes.Add(formType)
                End If
            End If
        Next formType
 
        For Each type As Type In formTypes
            Me.RadListControl1.Items.Add(type.Name)
        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,
Nikolay
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Sushant
Top achievements
Rank 1
answered on 08 May 2019, 10:56 AM
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
        Next

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 May 2019, 12:03 PM
Hello, Sushant,     

Thank you for sharing your solution with the community.

You can find useful as well the following threads:

https://stackoverflow.com/questions/30785319/how-to-get-all-forms-in-a-windows-form-application
https://www.codeproject.com/Questions/853501/How-I-Can-Get-List-Of-All-Forms-In-My-Project-Usin

I hope this information helps. 

Regards,
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.
Tags
General Discussions
Asked by
ali
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Sushant
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or