CodeRemoveEventStatement 类

定义

表示移除事件处理程序的语句。Represents a statement that removes an event handler.

public ref class CodeRemoveEventStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeRemoveEventStatement : System.CodeDom.CodeStatement
type CodeRemoveEventStatement = class
    inherit CodeStatement
Public Class CodeRemoveEventStatement
Inherits CodeStatement
继承
CodeRemoveEventStatement
属性

示例

下面的示例演示CodeRemoveEventStatement如何使用从事件中移除委托。The following example demonstrates use of a CodeRemoveEventStatement to remove a delegate from an event.

// 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 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.
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            

注解

CodeRemoveEventStatement可用于表示删除事件的事件处理程序的语句。CodeRemoveEventStatement can be used to represent a statement that removes an event handler for an event.

Event属性指定要从中删除事件处理程序的事件。The Event property specifies the event to remove the event handler from. Listener属性指定要删除的事件处理程序。The Listener property specifies the event handler to remove.

构造函数

CodeRemoveEventStatement()

初始化 CodeRemoveEventStatement 类的新实例。Initializes a new instance of the CodeRemoveEventStatement class.

CodeRemoveEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件和事件处理程序初始化 CodeRemoveEventStatement 类的新实例。Initializes a new instance of the CodeRemoveEventStatement class with the specified event and event handler.

CodeRemoveEventStatement(CodeExpression, String, CodeExpression)

使用指定的目标对象、事件名称和事件处理程序初始化 CodeRemoveEventStatement 类的新实例。Initializes a new instance of the CodeRemoveEventStatement class using the specified target object, event name, and event handler.

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives.

(继承自 CodeStatement)
Event

获取或设置要从中移除侦听器的事件。Gets or sets the event to remove a listener from.

LinePragma

获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs.

(继承自 CodeStatement)
Listener

获取或设置要移除的事件处理程序。Gets or sets the event handler to remove.

StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives.

(继承自 CodeStatement)
UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于