CodeRemoveEventStatement CodeRemoveEventStatement CodeRemoveEventStatement CodeRemoveEventStatement Class

定義

表示移除事件處理常式的陳述式。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
繼承
CodeRemoveEventStatementCodeRemoveEventStatementCodeRemoveEventStatementCodeRemoveEventStatement
屬性

範例

下列範例示範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() CodeRemoveEventStatement() CodeRemoveEventStatement()

初始化 CodeRemoveEventStatement 類別的新執行個體。Initializes a new instance of the CodeRemoveEventStatement class.

CodeRemoveEventStatement(CodeEventReferenceExpression, CodeExpression) CodeRemoveEventStatement(CodeEventReferenceExpression, CodeExpression) CodeRemoveEventStatement(CodeEventReferenceExpression, CodeExpression) CodeRemoveEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件與事件處理常式,初始化 CodeRemoveEventStatement 類別的新執行個體。Initializes a new instance of the CodeRemoveEventStatement class with the specified event and event handler.

CodeRemoveEventStatement(CodeExpression, String, CodeExpression) CodeRemoveEventStatement(CodeExpression, String, CodeExpression) CodeRemoveEventStatement(CodeExpression, String, CodeExpression) CodeRemoveEventStatement(CodeExpression, String, CodeExpression)

使用指定的目標物件、事件名稱和事件處理常式,初始化 CodeRemoveEventStatement 類別的新執行個體。Initializes a new instance of the CodeRemoveEventStatement class using the specified target object, event name, and event handler.

屬性

EndDirectives EndDirectives EndDirectives EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from CodeStatement)
Event Event Event Event

取得或設定將接聽程式移除的來源事件。Gets or sets the event to remove a listener from.

LinePragma LinePragma LinePragma LinePragma

取得或設定程式碼陳述式發生所在的行。Gets or sets the line on which the code statement occurs.

(Inherited from CodeStatement)
Listener Listener Listener Listener

取得或設定要移除的事件處理常式。Gets or sets the event handler to remove.

StartDirectives StartDirectives StartDirectives StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於