I have two projects: SQLtesting and Controls. Their physical locations are:

C:\My Documents\Visual Studio 2010\Projects\SQLtesting\SQLtesting\ [forms reside here]
C:\My Documents\Visual Studio 2010\Projects\Controls\Controls\ [forms reside here]

The code shown below works fine. I run it from the project SQLtesting. It loads a listbox and a checkedlistbox with the controls found on a form. I can change the value of the FormName field to any form within the SQLtesting project and get the form's controls. The forms are not actually opened/shown.

I would like to be able to access forms in other projects i.e.
C:\My Documents\Visual Studio 2010\Projects\Controls\Controls\
while running the code from the SQLtesting project.

Can anyone help me with this?
Thank you.

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles Button7.Click

        Dim [B]FormName [/B]As String = "Form1"
        Dim FullTypeName As String
        Dim FormInstanceType As Type
        Dim objForm As Form

        FullTypeName = Application.ProductName & "." & [B]FormName[/B] 
        FormInstanceType = Type.GetType(FullTypeName, True, True)
        objForm = CType(Activator.CreateInstance(FormInstanceType), Form)

        ListBox1.Sorted = True
        CheckedListBox1.Sorted = True
        CheckedListBox1.CheckOnClick = True

        Dim CtlType As Type
        Dim TypeName1 As String

        For Each ctl As Control In objForm.Controls  
            CtlType = ctl.GetType
            TypeName1 = CtlType.ToString.Substring(21) ' Remove system.windows.forms prefix
            Dim index As Integer = CheckedListBox1.FindStringExact(TypeName1)
            If index = -1 Then
            End If
            TypeName1 = TypeName1 & ":" & ctl.Name & ":" & ctl.Text
        Next ctl

    End Sub
5 Years
Discussion Span
Last Post by tfj

You need to add a reference to the other project.

When you have SQL Testing open go to Project/Add Reference on the menu bar of visual studio. On the Add Reference Window you should see .net/project/... Select browse and navigate to the Controls Folder. Inside the Controls folder you should see a folder name bin and inside bin you should see debug or release. If you built the Controls project as debug then go into the debug folder and then open the Controls.exe file.

In Sqltesting you should then be able to type Controls.Whatever you have in the project.


I was looking over your code. I didn't run it but see if this does the same thing. Other than the checklistbox.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'After adding a reference to your Controls app
        'you should be able to do
        'CheckForm as new Controls.Form1
        Dim CheckForm As New Form2

        For Each C As Control In CheckForm.Controls
            'C.GetType.Name only has the name not
            'the assembly or namespace

            ListBox2.Items.Add(C.GetType.Name & ":" & C.Name & ":" & C.Text)
    End Sub

Maybe you are looking for something like this.

This will create a form from another project without adding it
as a reference.

'Get all the controls from all forms in another windows forms app
Dim AssemblyFromFile As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("C:\Users\Administrator\Documents\Visual Studio 2008\Projects\CustomCombobox\CustomCombobox\bin\Debug\CustomCombobox.exe")
Dim Types As Type() = AssemblyFromFile.GetTypes

For Each Type As Type In Types

   If Type.BaseType Is GetType(Form) Then
        Dim F As Form = CType(Activator.CreateInstance(Type), Form)
        For Each C As Control In F.Controls
   End If

Edited by Unhnd_Exception: n/a


Thank you Unhnd_Exception for your effort and time providing 3 solutions. I feel you
are really close but not exactly what I need. I'm going to close this thread and
open a new one with more information. I hope you will review it and offer other

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.