CodeAttachEventStatement CodeAttachEventStatement CodeAttachEventStatement CodeAttachEventStatement Class

定義

表示將事件處理常式委派附加至事件的陳述式。Represents a statement that attaches an event-handler delegate to an event.

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

範例

下列範例程式碼示範CodeAttachEventStatement如何使用來附加事件處理常式與事件。The following example code demonstrates use of a CodeAttachEventStatement to attach an event handler with an event.

// 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可以用來代表語句, 以加入事件的事件處理常式委派。CodeAttachEventStatement can be used to represent a statement that adds an event-handler delegate for an event. Event屬性會指出要附加事件處理常式的事件。The Event property indicates the event to attach the event handler to. Listener屬性會指出要附加的事件處理常式。The Listener property indicates the event handler to attach.

建構函式

CodeAttachEventStatement() CodeAttachEventStatement() CodeAttachEventStatement() CodeAttachEventStatement()

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

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression) CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression) CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression) CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

使用指定的事件與委派,初始化 CodeAttachEventStatement 類別的新執行個體。Initializes a new instance of the CodeAttachEventStatement class using the specified event and delegate.

CodeAttachEventStatement(CodeExpression, String, CodeExpression) CodeAttachEventStatement(CodeExpression, String, CodeExpression) CodeAttachEventStatement(CodeExpression, String, CodeExpression) CodeAttachEventStatement(CodeExpression, String, CodeExpression)

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

屬性

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 attach an event-handler delegate to.

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 new event-handler delegate to attach to the event.

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)

適用於