Share via


CodeAttachEventStatement 類別

定義

表示將事件處理常式委派附加至事件的陳述式。

public ref class CodeAttachEventStatement : System::CodeDom::CodeStatement
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttachEventStatement : System.CodeDom.CodeStatement
type CodeAttachEventStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttachEventStatement = class
    inherit CodeStatement
Public Class CodeAttachEventStatement
Inherits CodeStatement
繼承
CodeAttachEventStatement
屬性

範例

下列範例程式代碼示範如何使用 CodeAttachEventStatement 附加事件處理程式與 事件。

// Defines a delegate creation expression that creates an EventHandler delegate pointing to a method named TestMethod.
CodeDelegateCreateExpression^ createDelegate1 = gcnew CodeDelegateCreateExpression( gcnew CodeTypeReference( "System.EventHandler" ),gcnew CodeThisReferenceExpression,"TestMethod" );

// Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
CodeAttachEventStatement^ attachStatement1 = gcnew CodeAttachEventStatement( gcnew CodeThisReferenceExpression,"TestEvent",createDelegate1 );

// A C# code generator produces the following source code for the preceeding example code:
//     this.TestEvent += new System.EventHandler(this.TestMethod);
// Defines a delegate creation expression that creates an EventHandler delegate pointing to a method named TestMethod.
CodeDelegateCreateExpression createDelegate1 = new CodeDelegateCreateExpression(
new CodeTypeReference( "System.EventHandler" ), new CodeThisReferenceExpression(), "TestMethod" );
// Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
CodeAttachEventStatement attachStatement1 = new CodeAttachEventStatement( new CodeThisReferenceExpression(), "TestEvent", createDelegate1 );

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

//     this.TestEvent += new System.EventHandler(this.TestMethod);
' Defines a delegate creation expression that creates an EventHandler delegate pointing to TestMethod.
Dim createDelegate1 As New CodeDelegateCreateExpression(New CodeTypeReference("System.EventHandler"), New CodeThisReferenceExpression(), "TestMethod")

' Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event.
Dim attachStatement1 As New CodeAttachEventStatement(New CodeThisReferenceExpression(), "TestEvent", createDelegate1)

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

'     AddHandler TestEvent, AddressOf Me.TestMethod

備註

CodeAttachEventStatement 可用來表示加入事件的事件處理程式委派的語句。 屬性 Event 會指出要附加事件處理程式的事件。 屬性 Listener 會指出要附加的事件處理程式。

建構函式

CodeAttachEventStatement()

初始化 CodeAttachEventStatement 類別的新執行個體。

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件與委派,初始化 CodeAttachEventStatement 類別的新執行個體。

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

使用包含事件、事件名稱和事件處理常式的指定物件,初始化 CodeAttachEventStatement 類別的新執行個體。

屬性

EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
Event

取得或設定要附加事件處理常式委派的目的事件。

LinePragma

取得或設定程式碼陳述式發生所在的行。

(繼承來源 CodeStatement)
Listener

取得或設定要附加至事件的新事件處理常式委派。

StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於