Event Removal in VB

  • Thread starter Thread starter Beebs
  • Start date Start date
B

Beebs

I asked last week about an ObjectDisposedException when using the SIP
through multiple forms and I got a fairly resonable answer, but I have
found a more streamlined approach via the archives but it is written
in C#. Can anyone help me translate this into VB since I've had no
luck thus far?

I need this in my form's closed event:

this.inputPanel.EnabledChanged -= new
EventHandler(inputPanel_EnabledChanged);

I've tried this, but I get a bunch of errors so it's obviously not
even close to being right:

Me.InputPanel.EnabledChanged = New EventHandler(AddressOf
InputPanel_EnabledChanged)

Thanks...
 
I can find virtually no help on RemoveEventHandler and never worked
with delegates or reflection or anything similar, so now I'm totally
lost as to how to simply remove my event handler...
 
Well, I keep trying, and I'm getting nowhere...I put this in my form's
class declarations:

Delegate Function myMethodDelegate(ByVal sender As Object, ByVal e As
System.EventArgs)

And in my form's closed event I put this code:

Dim myDelegate As New myMethodDelegate(AddressOf
Me.InputPanel1_EnabledChanged)

System.Reflection.EventInfo.RemoveEventHandler(sender,
InputPanel1_EnabledChanged(sender, e))

And I get an error for each line. For the Dim line I get

Method 'Private Sub InputPanel1_EnabledChanged(sender As Object, e As
System.EventArgs)' does not have the same signature as delegate
'Delegate Function myMethodDelegate(sender As Object, e As
System.EventArgs) As Object'.

Since InputPanel1_EnabledChanged handles an event and delegates
cannot, I'm totally lost.

The error I get on the second line is:

Reference to a non-shared member requires an object reference.

I'm clueless here as well...can someone help me on this simple task of
removing an event handler...I'm certainly trying, just not getting
anywhere.
 
Back
Top