Freigeben über


CodeRemoveEventStatement-Klasse

Stellt eine Anweisung dar, die einen Ereignishandler entfernt.

Namespace: System.CodeDom
Assembly: System (in system.dll)

Syntax

'Declaration
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeRemoveEventStatement
    Inherits CodeStatement
'Usage
Dim instance As CodeRemoveEventStatement
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class CodeRemoveEventStatement : CodeStatement
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class CodeRemoveEventStatement : public CodeStatement
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CodeRemoveEventStatement extends CodeStatement
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class CodeRemoveEventStatement extends CodeStatement

Hinweise

Mit CodeRemoveEventStatement kann eine Anweisung dargestellt werden, die einen Ereignishandler für ein Ereignis entfernt.

Die Event-Eigenschaft gibt das Ereignis an, für das der Ereignishandler entfernt werden soll. Die Listener-Eigenschaft gibt den zu entfernenden Ereignishandler an.

Beispiel

Im folgenden Beispiel wird veranschaulicht, wie mit einem CodeRemoveEventStatement ein Delegat aus einem Ereignis entfernt wird.

' 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            
// 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);
// Creates a delegate of type System.EventHandler pointing to a method named OnMouseEnter.
CodeDelegateCreateExpression^ mouseEnterDelegate = gcnew CodeDelegateCreateExpression( gcnew CodeTypeReference( "System.EventHandler" ),gcnew CodeThisReferenceExpression,"OnMouseEnter" );

// Creates a remove event statement that removes the delegate from the TestEvent event.
CodeRemoveEventStatement^ removeEvent1 = gcnew CodeRemoveEventStatement( gcnew CodeThisReferenceExpression,"TestEvent",mouseEnterDelegate );

// A C# code generator produces the following source code for the preceeding example code:
//     this.TestEvent -= new System.EventHandler(this.OnMouseEnter);
// 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 VJ# code generator produces the following source code for 
// the preceeding example code:
//     this.TestEvent -= new System.EventHandler(this.OnMouseEnter);

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

CodeRemoveEventStatement-Member
System.CodeDom-Namespace