views:

107

answers:

0

Hello,

Normally I setup events like this...

Public Delegate Sub MySpecialEventHandler(sender as object, e as mySpecialEventEventArgs)  '  ...I will not show the implementation of mySpecialEventArgs.
Public Event MySpecialEvent as MySpecialEventHandler  

Private Sub OnMySpecialEvent(newStatus as string)  
     Raise Event MySpecialEvent(Me,New mySpecialEventEventArgs(newStatus))  
End Sub

I have an interface...it looks like this...

Public Interface IWizardUserControl
    ReadOnly Property ShowNavigatePrevious() As Boolean
    ReadOnly Property ShowNavigateNext() As Boolean
    ReadOnly Property ShowNavigateFinish() As Boolean
    ReadOnly Property ShowNavigateCancel() As Boolean
    ReadOnly Property Description() As String
    ReadOnly Property StepCaption() As String
    ReadOnly Property PageImage() As System.Drawing.Image
    ReadOnly Property PageHelpText() As String
    Property IsValid() As Boolean
    Sub OnValidStatusChanged(ByVal validStatus As Boolean)
    Event ValidStatusChanged()
End Interface

I would like the event setup such as what you see above to be implemented in the above interface.

When you setup a delegate in the interface. No errors. But when you try to implement the delegate in the userControl Visual studio says "Delegates cannot implement interface methods" .

My goal is to have a controller class that would cast the derived class as the interface and then add a handler for the interfaces event.

Any help would be appreciated. Thanks in advance.

EDIT - I took John Saunders advice and drilled into the web.ui class. Here is what I did and it is working perfectly.

In the interface I added/changed the following...

Sub OnValidStatusChanged(ByVal validStatus As Boolean)  
Sub ValidStatusChangedHandler(ByVal sender As Object, ByVal e AsValidStatusChangedEventArgs)  
Event ValidStatusChanged As EventHandler

Most relevant point being that I ValidStatusChangedHandler is declared as a Sub not a delegate.

I implemented those in my derived class as follows...

Protected Event ValidStatusChanged As EventHandler Implements IWizardUserControl.ValidStatusChanged

Protected Sub ValidStatusChangedHandler(ByVal sender As Object, ByVal e As ValidStatusChangedEventArgs) Implements IWizardUserControl.ValidStatusChangedHandler
    OnValidStatusChanged(e.ValidStatus)
End Sub

Private Sub OnValidStatusChanged(ByVal status As Boolean) Implements IWizardUserControl.OnValidStatusChanged
    RaiseEvent ValidStatusChanged(Me, New ValidStatusChangedEventArgs(status))
End Sub

Finally in the controller class I am doing this...

Dim iwp As IWizardUserControl = DirectCast(wizardUserControl, IWizardUserControl)
AddHandler iwp.ValidStatusChanged, AddressOf iwp.ValidStatusChangedHandler

Works like a charm.

Seth