Question Plugin Sub Call

napoleonjones

Member
Joined
Mar 24, 2007
Messages
18
Programming Experience
Beginner
I am having a very hard time trying to figure this out. I am developing a application which is just basically a menu system and most of the actual code will be in plugins. I want the code to loop through and find the assemblies and load them. Once the assembly is loaded, I want it to create a button on the form and wire that to the "run" procedure of the plugin. I am having trouble wring the button to the run procedure. I don't have any code to post since haven't written any for this. Can somebody point me in the right direction?

Thanks
 
I've read that already, but it is a little different from what I am wanting to do. That example loads all the plugins into a listbox and already has a button on the form which handles the click event. What I want to do is generate a button for each plugin dynamically and wire it up to a plugin. I am having problems wiring the button to the plugin code.
 
For example use the Text property of each button to place something you need to identify which plugin corresponds to that button. In the common event handler for all your plugin buttons you check this identifyer and create/get the appropriate plugin instance, for which you call the Run method. Like for example you have an array of 2 plugins and you text the buttons "0" and "1", you get this number and get the item in array of that index. You can even put the plugin instance in the Tag property of each button and just grab it from there directly.
VB.NET:
Private Sub buttons_click(ByVal sender As Object, ByVal e As EventArgs)
    Dim b As Button = sender
    Dim p As IPlugin = b.Tag
    p.Run()
End Sub
 
Back
Top