hi all,
is this possible?
i plan to create a MDI Form for the executable. then use classes for forms. can i reference this classes at runtime?
thanks
Printable View
hi all,
is this possible?
i plan to create a MDI Form for the executable. then use classes for forms. can i reference this classes at runtime?
thanks
Are you trying to do some sort of plug-in architecture?
You can do what you are asking, I am just trying to understand why you are asking for it.
hi,Quote:
Originally Posted by Negative0
forgive me but i am not familiar with the plug-in architecture term.
but what i'm trying to do is that for example, i already created the MDI Form which serves as the Main Form. i built this as an exe file. so basically this will be the file to run the application. this mdi form will have a menu that will be created at runtime as well. i will be using a database table to hold the items in the menu. then clicking a menu will basically load a child form.
for all the child forms, i will be using classes.
so instead of editing the whole project when adding child forms, i plan to just create a class for a form then built the .dll file. then copy it to a directory where all the applications .dll resides. then add a record to the table for this particular form.
thanks.
So you want to load a DLL on the fly and use classes from it?
If so, I have a plug-in example on my website that shows you how to create a plugin architecture in a program. It is in C# and it focuses on a plugin that draws on an image, but you should be able to take that and extrapolate some of the information that you need:
http://johnkoerner.net/index.php?/ar...ture-in-C.html
i'll check it out.
thanks.
hi,
i've been trying to follow the video provided on the link. at first i thought it would be easy to convert C# to VB.Net but it seems like its harder than i thought. so after spending some time trying, i'm wanting to give up doing this in C#.Net.
my apologies as i'm not able to follow the instructions on the video. i'm having a hard-time understanding the codes well since i'm a VB.Net programmer and C#.Net is totally alien to me.
do you have a vb.net sample?
thanks.
The basic steps are the same, don't worry so much about how it is coded in my example:
1.) Create an interface.
2.) Implement that interface in your plugin (or your form in your case)
3.) In your main app, loop through all DLLs in a specific folder and if they implement your interface, add them to a list for use later.
4.) When you are ready, call the plugins method that is implemented in the interface.
Here is a quick example I threw together:
For the interface:
PROJECT1 - The other two projects need a reference to this project.
In my class that implements the interface:Code:Public Interface TestInterface
Sub DoWork(ByVal f As Form)
End Interface
PROJECT2
PROJECT3Code:Imports InterfaceTesting
Imports System.Windows.Forms
Public Class Class1
Implements TestInterface
Public Sub DoWork(ByVal f As Form) Implements InterfaceTesting.TestInterface.DoWork
Dim myForm As New Form1
myForm.MdiParent = f
myForm.Show()
End Sub
End Class
In my program that loads the plugins:
Code:Imports System.Reflection
Imports InterfaceTesting
Public Class Form1
Dim Plugs As List(Of TestInterface)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each p As TestInterface In Plugs
p.DoWork(Me)
Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.IsMdiContainer = True
Plugs = New List(Of TestInterface)
Dim files() As String = IO.Directory.GetFiles(Application.StartupPath & "\Plugins", "*.dll")
Dim assm As Assembly
For Each f As String In files
assm = Assembly.LoadFile(f)
For Each t As Type In assm.GetTypes()
If Not t.GetInterface("TestInterface") Is Nothing Then
Dim plugin As TestInterface = DirectCast(Activator.CreateInstance(t), TestInterface)
Plugs.Add(plugin)
End If
Next
Next
End Sub
End Class
thanks for the detailed sample... found it really helpful. i'm able to load forms now using this.
so basically as long as i load the form, each and every event in the form will work like when invoked the usual way?
Yes, just remember everything that is being done is in the class, not your main application, so if you need to communicate between forms, you are going to have to do a little bit more work.
thanks...
i was just thinking that if two of my forms needed to communicate, maybe i should put both forms in one class instead as long as the forms are related to each other like a master-detail form? or is there any better way?
since i think there will be situations that forms will need to communicate.
hi again,
i'm having the need to have my forms (not in same class) to communicate with each other. unfortunately i don't know how i can accomplish this.
can someone help me?
thanks