VB.net 2010中另一个项目中的Access窗体

VB.net 2010中另一个项目中的Access窗体,vb.net,Vb.net,我正在使用VB.net 2010,我有两个项目:SQLtesting和控件。它们的实际位置是: C:\My Documents\Visual Studio 2010\Projects\SQLtesting\SQLtesting\[表单位于此处] C:\My Documents\Visual Studio 2010\Project\Controls\Controls\[表单位于此处] 下面显示的代码工作正常。我从项目SQLtesting运行它。它加载一个listbox和一个checkedlistb

我正在使用VB.net 2010,我有两个项目:SQLtesting控件。它们的实际位置是:

C:\My Documents\Visual Studio 2010\Projects\SQLtesting\SQLtesting\[表单位于此处] C:\My Documents\Visual Studio 2010\Project\Controls\Controls\[表单位于此处]

下面显示的代码工作正常。我从项目SQLtesting运行它。它加载一个listbox和一个checkedlistbox,其中包含在表单上找到的控件。我可以将ProjAndForm字段的值更改为SQLtesting项目中的任何表单,并获取表单的控件。表单没有实际打开/显示,也不应该打开/显示

我希望能够访问其他项目的表格,即。 *C:\My Documents\Visual Studio 2010\Project\Controls\Controls* 在运行SQLtesting项目中的代码时

在实际使用中,(当此应用程序为.exe时),用户(开发人员)将输入项目名称、表单名称以及其他所需内容,然后单击按钮7。在我的示例代码中不能有任何硬编码。此应用程序将安装在个人电脑或网络上,因此代码必须根据开发人员输入的内容工作

我真正需要的是一种指向另一个项目和表单并仍然使用我的代码的方法。 我相信所需的陈述将先于我的以下3个陈述

ProjAndForm = "SQLtesting.Form1"
FormInstanceType = Type.GetType(ProjAndForm, True, True)
objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
当前,如果我将ProjAndForm的值更改为“Controls.Form66”则会在FormInstanceType语句中引发异常

无法从程序集“SQLtesting”加载类型“Controls.Form66”, 版本=1.0.0.0,区域性=中性,PublicKeyToken=空。

正如我上面所说的,只要我愿意,代码就可以很好地工作并提供我想要的东西 在当前项目SQLtesting中引用表单

有人能帮我吗

多谢各位

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)句柄按钮7。单击

    Dim CtlType As Type
    Dim FormInstanceType As Type
    Dim index As Integer 
    Dim objForm As Form
    Dim ProjAndForm As String
    Dim TypeName1 As String
    Dim TypeName2 As String

    ListBox1.Sorted = True
    ListBox1.Items.Clear()

    CheckedListBox1.Sorted = True
    CheckedListBox1.Items.Clear()
    CheckedListBox1.CheckOnClick = True

    ProjAndForm = "SQLtesting.Form1"
    FormInstanceType = Type.GetType(ProjAndForm, True, True)
    objForm = CType(Activator.CreateInstance(FormInstanceType), Form)

    For Each ctl As Control In objForm.Controls 
        CtlType = ctl.GetType
        TypeName1 = CtlType.ToString.Substring(21) ' Remove system.windows.forms prefix
        index = 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

您要查找的是Assembly.LoadFrom。为此,您将需要exe或dll

Dim path As String = "youassemblywitpath.dll"
Dim ass As Assembly = Assembly.LoadFrom(path)
ProjAndForm = "SQLtesting.Form1"
FormInstanceType = ass.GetType(ProjAndForm)
objForm = CType(Activator.CreateInstance(FormInstanceType), Form)

或者你也可以用。

chrisse1:哇!这正是我需要的。我希望你能回答我今后提出的任何问题。谢谢。我接受这个答案。我是不是要点击某个东西来表明这一点?这是我的第一篇文章。