Expand Minimize

'Custom' modifier is not valid on events declared without explicit delegate types

Unlike a non-custom event, a Custom Event declaration requires an As clause following the event name that explicitly specifies the delegate type for the event.

Non-custom events can be defined either with an As clause and an explicit delegate type, or with a parameter list immediately following the event name.

Error ID: BC31122

To correct this error

  1. Define a delegate with the same parameter list as the custom event.

    For example, if the Custom Event was defined by Custom Event Test(ByVal sender As Object, ByVal i As Integer), then the corresponding delegate would be the following.

    Delegate Sub TestDelegate(ByVal sender As Object, ByVal i As Integer)
    
  2. Replace the parameter list of the custom event with an As clause specifying the delegate type.

    Continuing with the example, Custom Event declaration would be rewritten as follows.

    Custom Event Test As TestDelegate
    

This example declares a Custom Event and specifies the required As clause with a delegate type.

Delegate Sub TestDelegate(ByVal sender As Object, ByVal i As Integer)
Custom Event Test As TestDelegate
    AddHandler(ByVal value As TestDelegate)
        ' Code for adding an event handler goes here. 
    End AddHandler 

    RemoveHandler(ByVal value As TestDelegate)
        ' Code for removing an event handler goes here. 
    End RemoveHandler 

    RaiseEvent(ByVal sender As Object, ByVal i As Integer)
        ' Code for raising an event goes here. 
    End RaiseEvent 
End Event
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft