Condividi tramite


CodeAttachEventStatement Classe

Definizione

Rappresenta un'istruzione che collega un delegato del gestore eventi a un evento.

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
Ereditarietà
CodeAttachEventStatement
Attributi

Esempio

Il codice di esempio seguente illustra l'uso di un CodeAttachEventStatement oggetto per associare un gestore eventi a un evento.

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

Commenti

CodeAttachEventStatement può essere usato per rappresentare un'istruzione che aggiunge un delegato del gestore eventi per un evento. La Event proprietà indica l'evento a cui associare il gestore eventi. La Listener proprietà indica il gestore eventi da associare.

Costruttori

Nome Descrizione
CodeAttachEventStatement()

Inizializza una nuova istanza della classe CodeAttachEventStatement.

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

Inizializza una nuova istanza della CodeAttachEventStatement classe utilizzando l'evento e il delegato specificati.

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

Inizializza una nuova istanza della CodeAttachEventStatement classe utilizzando l'oggetto specificato contenente l'evento, il nome dell'evento e il delegato del gestore eventi.

Proprietà

Nome Descrizione
EndDirectives

Ottiene un CodeDirectiveCollection oggetto che contiene direttive end.

(Ereditato da CodeStatement)
Event

Ottiene o imposta l'evento a cui associare un delegato del gestore eventi.

LinePragma

Ottiene o imposta la riga in cui si verifica l'istruzione del codice.

(Ereditato da CodeStatement)
Listener

Ottiene o imposta il nuovo delegato del gestore eventi da associare all'evento.

StartDirectives

Ottiene un CodeDirectiveCollection oggetto contenente le direttive start.

(Ereditato da CodeStatement)
UserData

Ottiene i dati definibili dall'utente per l'oggetto corrente.

(Ereditato da CodeObject)

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a