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)

適用於