Search code examples
vb.netfunctioneventsevent-handlingaddhandler

Keep getting error when using eventhandler, syntax error


I am trying to control when a event is firing and having some issus. This is what I tried ,following the documentation on MSD

Can anybody see the error here?

BC30677 Visual Basic or statement event operand must be a dot-qualified expression or a simple name.

Public Class Formx

Public Sub test()

        Dim Objectfx As New Formx()

        RemoveHandler Objectfx.Button2_Click(), AddressOf Button2_Click

    End Sub

end Class

Solution

  • You remove the association of a delegate to its event handler with this syntax.

     RemoveHandler Objectfx.Click, AddressOf Button2_Click
    

    It seems that Objectfx is a button not a Form but in any case the first parameter of RemoveHandler is the delegate that has been assigned with a compatible event handler passed as second argument