"Daniel Friend" <da*@donotspam.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
I have an application and use custom user controls as plugins.
Is there any way to communicate back and forth from control
to app. NOTE: The control is not referenced in the app
I'd do it this way:
Every Plug-In implements this Interface:
Public Interface IPlugIn
WriteOnly Property ParentForm as IPlugInContainer
' Any other properties/methods that the main application
' might ask /every/ plug-in to do.
End Interface
Have the main application implement this Interface:
Public Interface IPlugInContainer
' Include any properties/methods that a Plug-In might need.
' /Don't/ rely on properties that /happen/ to be on the Form
End Interface
Both of these exist in an assembly common to both the application
and the plug-ins. They form a well-defined communication channel
between plug-in and application; a common currency that the two
can "converse" in.
As you load [each] plug-in into your application, assign the Form
to the [IPlugIn].ParentForm property (you *know* it's there
because the plug-in, whatever /else/ it does, implements the Interface),
as in
' Get Plug-In object
oLoadedPlugIn = Activator.CreateInstance( ...
' Pass the parent application [form] reference to the plug-in
DirectCast( oLoadedPlugIn, IPlugIn ).ParentForm _
= DirectCast( Me, IPlugInContainer )
Your plug-in can now access anything in the IPlugInContainer
Interface (which, of course, calls methods in the main application).
HTH,
Phill W.