Remove Event Handlers in C#.NET

  • Thread starter Thread starter Prasad Dannani
  • Start date Start date
P

Prasad Dannani

Hi,

I am currently working on C#.

I need to temporarity add remove event handlers
which i was done in VB.NET using Addhandler and RemoveHandler functions.

How to do it in c#

Thanks in Advance
Prasad Dannani
 
An example from our Instant C# VB.NET to C# converter:
VB:
AddHandler ControlA.Click, New ControlA.SomeEventHandler(AddressOf
ControlA_Click)
C#:
ControlA.Click += new ControlA.SomeEventHandler(ControlA_Click);

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 
below you have a sample with 2 way of removing event handlers....
------
class HasEvent
{
public event EventHandler SomethingHappened;

// here I simply remove all event handler,
// could be done only from the object defining the event
public void DontBother()
{
SomethingHappened = null;
}
}
class UseEvent
{
void RegisterUnregister(HasEvent he)
{
he.SomethingHappened += new EventHandler(BeAlert); // register an
event handler
he.SomethingHappened -= new EventHandler(BeAlert); // unregister the
same event handler
}
void BeAlert(object source, EventArgs e)
{
// here I'm notified of the event
}
}
 
Back
Top