Okay got at lot further for now, but have a following question
I have a main program wihich merges a menu created in a seperate dll. This mainprogram is an MDIcontainer. How can I make it so that the forms in thd dll use the form of the main program as mdiparent.
these are the codes i have:
testmodule.dll (seperate dll):
class menu
Private _hoofdIn As New MenuItem
Public Function getmenu()
Dim m As New MainMenu
_hoofdIn.Text = "TestModule"
_hoofdIn.MenuItems.Add("subtest", New EventHandler(AddressOf _sub1_Click))
m.MenuItems.Add(_hoofdIn)
Return m
End Function
Protected Sub _sub1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sf As New sub1
sf.Show()
End Sub
testmodule.dll also contains sub1 form.
The main program:
Imports System.reflection
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
Me.MenuItem1.Text = "bestand"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "sluiten"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(104, 104)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "merge"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
End
End Sub
Private path As String = "c:\testmod"
Private objmenu As MainMenu
Public Sub CreateMenu()
Dim refmodule As [Assembly] = [Assembly].LoadFile(path & "\testmodule.dll")
Dim t As Type = refmodule.GetType("testmodule.menu")
Dim obj As Object = Activator.CreateInstance(t)
Dim ar As Menu = obj.getmenu()
Me.MainMenu1.MergeMenu(ar)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CreateMenu()
End Sub
End Class
[If you could make your newsreader wrap lines at about 70 characters it
would make your posts easier to reply to, by the way.]
filip stas said:
creating dll files containing forms so they can be applied as sort of
an add-in in to a main program. I want to call those dll files and then
dynamically add menus for the forms contained in the dll into the main
program
In that case use Assembly.Load, Assembly.LoadFrom or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.
You then use Assembly.GetType(String) to get the appropriate type, then
instantiate it by reflection etc.