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.MenuIt ems.Add("subtes t", New EventHandler(Ad dressOf _sub1_Click))
m.MenuItems.Add (_hoofdIn)
Return m
End Function
Protected Sub _sub1_Click(ByV al sender As Object, ByVal e As System.EventArg s)
Dim sf As New sub1
sf.Show()
End Sub
testmodule.dll also contains sub1 form.
The main program:
Imports System.reflecti on
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.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
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.SuspendLayou t()
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( ) {Me.MenuItem2})
Me.MenuItem1.Te xt = "bestand"
'
'MenuItem2
'
Me.MenuItem2.In dex = 0
Me.MenuItem2.Te xt = "sluiten"
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(104, 104)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 0
Me.Button1.Text = "merge"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(292, 273)
Me.Controls.Add (Me.Button1)
Me.IsMdiContain er = 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.EventArg s) 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.dl l")
Dim t As Type = refmodule.GetTy pe("testmodule. menu")
Dim obj As Object = Activator.Creat eInstance(t)
Dim ar As Menu = obj.getmenu()
Me.MainMenu1.Me rgeMenu(ar)
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
CreateMenu()
End Sub
End Class
"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@news.microsof t.com...
[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 <fi********@pan dora.be> wrote:
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.LoadFr om or one of the
similarly named methods. They vary in subtle ways, so be careful which
you pick.
You then use Assembly.GetTyp e(String) to get the appropriate type, then
instantiate it by reflection etc.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too