You have described the need for a callback mechanism. This can be achieved through the use of a Delegate.
Please read through the following for information on Delegates:
1.
Delegates[
^]
2.
Action Delegate[
^]
Assume that the following class is in your DLL Project B. In this example, I have used the method signature of your EnableButton method.
Public Class ClassCallBackTest
' Option 1, define your callback signature as a method with a boolean paramter
Public Delegate Sub CallBack(ByVal enable As Boolean)
Private ConstructorPassedCallBack As CallBack ' local copy of Delegate passed in constructor
Public Sub New(ByVal CallBack As CallBack)
Me.ConstructorPassedCallBack = CallBack
End Sub
Public Sub CallTheCallBack()
If ConstructorPassedCallBack IsNot Nothing Then ConstructorPassedCallBack(True)
End Sub
' Option 2, pass then callback to the method needing to call it
Public Sub CallACallBack(ByVal CallBack As CallBack, ByVal enable As Boolean)
If CallBack IsNot Nothing Then CallBack(enable)
End Sub
' Option 3, pass then callback as an Action(Of Boolean) to the method needing to call it
' This just a different way to define the required signature.
Public Sub CallACallBack2(ByVal CallBack As System.Action(Of Boolean), ByVal enable As Boolean)
If CallBack IsNot Nothing Then CallBack(enable)
End Sub
End Class
Here is an example of the usage.
Public Class Form1
Private Sub CallBackMethod(ByVal enable As Boolean)
MsgBox("Enabled = " & enable.ToString())
End Sub
Private Sub CallBackMethod2(ByVal enable As Boolean)
MsgBox("CallBackMethod2 called. Enabled = " & enable.ToString())
End Sub
Private Sub CallBackMethod3(ByVal enable As Boolean)
MsgBox("CallBackMethod3 called. Enabled = " & enable.ToString())
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim test As New ClassLibrary1.ClassCallBackTest(AddressOf CallBackMethod)
test.CallTheCallBack() ' use the constructor callback
test.CallACallBack(AddressOf CallBackMethod2, False)
test.CallACallBack2(AddressOf CallBackMethod3, True)
End Sub
End Class