Ich habe eine Funktion geschrieben wo man eine Form aus der ClassLibrary aufrufen kann.
In der Funktion Pfad zur DLL angeben und Name der Form die in der ClassLibrary DLL ist.
Folgende Importe werden benötigt:
Die Funktion:
Beispiel Aufruf einer Form in ClassLibrary DLL:
Viel Spaß
In der Funktion Pfad zur DLL angeben und Name der Form die in der ClassLibrary DLL ist.
Folgende Importe werden benötigt:
Die Funktion:
VB.NET-Quellcode
- ''' <summary>Ruft eine Form auf in einer DLL</summary>
- ''' <param name="DLLpath">Pfad zur DLL (Beispiel: C:\TEST.dll)</param>
- ''' <param name="FormName">Form Name in DLL (Beispiel: Form1 oder frmMain)</param>
- Public Sub CallDLLForm(ByVal DLLpath As String, ByVal FormName As String)
- Dim DLLFilenameEx As String = Path.GetFileName(DLLpath)
- Dim Filename As String = Path.GetFileNameWithoutExtension(DLLpath)
- Try
- Dim A As [Assembly] = [Assembly].LoadFrom(DLLpath)
- Dim B As [Module] = A.GetModule(DLLFilenameEx)
- Dim C As Type = B.GetType(Filename & "." & FormName)
- Dim D As Form = DirectCast(Activator.CreateInstance(C), Form)
- D.ShowDialog()
- Catch ex As Exception
- MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
Beispiel Aufruf einer Form in ClassLibrary DLL:
VB.NET-Quellcode
- 'Form1 aus ClassLibrary1.dll aufrufen
- CallDLLForm(Application.StartupPath & "\ClassLibrary1.dll", "Form1")
- 'Form1 aus ClassLibrary2.dll aufrufen
- CallDLLForm(Application.StartupPath & "\ClassLibrary2.dll", "Form1")
- 'Form1 aus ClassLibrary1.dll aufrufen
- CallDLLForm("C:\ClassLibrary1.dll", "Form1")
- 'Form2 aus ClassLibrary1.dll aufrufen
- CallDLLForm("C:\ClassLibrary1.dll", "Form2")
Viel Spaß