CodeAttachEventStatement Class
Represents a statement that attaches an event-handler delegate to an event.
For a list of all members of this type, see CodeAttachEventStatement Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeAttachEventStatement
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeAttachEventStatement Inherits CodeStatement [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeAttachEventStatement : CodeStatement [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeAttachEventStatement : public CodeStatement [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeAttachEventStatement extends CodeStatement
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
CodeAttachEventStatement can be used to represent a statement that adds an event-handler delegate for an event. The Event property indicates the event to attach the event handler to. The Listener property indicates the event handler to attach.
Example
[Visual Basic, C#, C++] The following example code demonstrates use of a CodeAttachEventStatement to attach an event handler with an event.
[Visual Basic] ' 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 [C#] // 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); [C++] // Defines a delegate creation expression that creates an EventHandler delegate pointing to a method named TestMethod. CodeDelegateCreateExpression* createDelegate1 = new CodeDelegateCreateExpression( new CodeTypeReference( S"System.EventHandler" ), new CodeThisReferenceExpression(), S"TestMethod" ); // Attaches an EventHandler delegate pointing to TestMethod to the TestEvent event. CodeAttachEventStatement* attachStatement1 = new CodeAttachEventStatement( new CodeThisReferenceExpression(), S"TestEvent", createDelegate1 ); // A C# code generator produces the following source code for the preceeding example code: // this.TestEvent += new System.EventHandler(this.TestMethod);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)