This documentation is archived and is not being maintained.

CodeRemoveEventStatement Class

Represents a statement that removes an event handler.

For a list of all members of this type, see CodeRemoveEventStatement Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeStatement
         System.CodeDom.CodeRemoveEventStatement

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeRemoveEventStatement
   Inherits CodeStatement
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeRemoveEventStatement : CodeStatement
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeRemoveEventStatement : public
   CodeStatement
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeRemoveEventStatement extends CodeStatement

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

CodeRemoveEventStatement can be used to represent a statement that removes an event handler for an event.

The Event property specifies the event to remove the event handler from. The Listener property specifies the event handler to remove.

Example

[Visual Basic, C#, C++] The following example demonstrates use of a CodeRemoveEventStatement to remove a delegate from an event.

[Visual Basic] 
' Creates a delegate of type System.EventHandler pointing to a method named OnMouseEnter.
Dim mouseEnterDelegate As New CodeDelegateCreateExpression(New CodeTypeReference("System.EventHandler"), New CodeThisReferenceExpression(), "OnMouseEnter")
' Creates a remove event statement that removes the delegate from the TestEvent event.
Dim removeEvent1 As New CodeRemoveEventStatement(New CodeThisReferenceExpression(), "TestEvent", mouseEnterDelegate)

' A Visual Basic code generator produces the following source code for the preceeding example code:

'   RemoveHandler TestEvent, AddressOf Me.OnMouseEnter            

[C#] 
// Creates a delegate of type System.EventHandler pointing to a method named OnMouseEnter.
CodeDelegateCreateExpression mouseEnterDelegate = new CodeDelegateCreateExpression( new CodeTypeReference("System.EventHandler"), new CodeThisReferenceExpression(), "OnMouseEnter" );
// Creates a remove event statement that removes the delegate from the TestEvent event.
CodeRemoveEventStatement removeEvent1 = new CodeRemoveEventStatement( new CodeThisReferenceExpression(), "TestEvent", mouseEnterDelegate );

// A C# code generator produces the following source code for the preceeding example code:

//     this.TestEvent -= new System.EventHandler(this.OnMouseEnter);

[C++] 
// Creates a delegate of type System.EventHandler pointing to a method named OnMouseEnter.
CodeDelegateCreateExpression* mouseEnterDelegate = new CodeDelegateCreateExpression( new CodeTypeReference(S"System.EventHandler"), new CodeThisReferenceExpression(), S"OnMouseEnter" );
// Creates a remove event statement that removes the delegate from the TestEvent event.
CodeRemoveEventStatement* removeEvent1 = new CodeRemoveEventStatement( new CodeThisReferenceExpression(), S"TestEvent", mouseEnterDelegate );

// A C# code generator produces the following source code for the preceeding example code:

//     this.TestEvent -= new System.EventHandler(this.OnMouseEnter);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeRemoveEventStatement Members | System.CodeDom Namespace

Show: