Share via


CodeAttachEventStatement Classe

Definição

Representa uma instrução que anexa um delegado do manipulador de eventos a um 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
Herança
CodeAttachEventStatement
Atributos

Exemplos

O código de exemplo a seguir demonstra o uso de um CodeAttachEventStatement para anexar um manipulador de eventos com um evento.

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

Comentários

CodeAttachEventStatement pode ser usado para representar uma instrução que adiciona um delegado de manipulador de eventos para um evento. A Event propriedade indica o evento ao qual anexar o manipulador de eventos. A Listener propriedade indica o manipulador de eventos a ser anexado.

Construtores

CodeAttachEventStatement()

Inicializa uma nova instância da classe CodeAttachEventStatement.

CodeAttachEventStatement(CodeEventReferenceExpression, CodeExpression)

Inicializa uma nova instância da classe CodeAttachEventStatement usando o evento e o delegado especificados.

CodeAttachEventStatement(CodeExpression, String, CodeExpression)

Inicializa uma nova instância da classe CodeAttachEventStatement usando o objeto especificado contendo o evento, o nome do evento e o delegado do manipulador de eventos.

Propriedades

EndDirectives

Obtém um objeto CodeDirectiveCollection que contém as diretivas de término.

(Herdado de CodeStatement)
Event

Obtém ou define o evento ao qual anexar um delegado do manipulador de eventos.

LinePragma

Obtém ou define a linha em que ocorre a declaração de código.

(Herdado de CodeStatement)
Listener

Obtém ou define o novo delegado de manipulador de eventos a anexar ao evento.

StartDirectives

Obtém um objeto CodeDirectiveCollection que contém as diretivas de início.

(Herdado de CodeStatement)
UserData

Obtém os dados definidos pelo usuário para o objeto atual.

(Herdado de CodeObject)

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a