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
ListBox1.Items.Clear()
CheckedListBox1.Sorted = True
CheckedListBox1.Items.Clear()
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
CheckedListBox1.Items.Add(TypeName1)
End If
TypeName1 = TypeName1 & ":" & ctl.Name & ":" & ctl.Text
ListBox1.Items.Add(TypeName1.ToString)
Next ctl
End Sub