CodeAttachEventStatement クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ Public Class CodeAttachEventStatement Inherits CodeStatement
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class CodeAttachEventStatement : CodeStatement
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] public ref class CodeAttachEventStatement : public CodeStatement

CodeAttachEventStatement を使用して、イベント ハンドラのデリゲートをイベントに追加するステートメントを表すことができます。Event プロパティは、イベント ハンドラを結び付けるイベントを表します。Listener プロパティは、結びつけるイベント ハンドラを表します。

CodeAttachEventStatement を使用してイベント ハンドラをイベントに結び付ける方法を示すコード例を次に示します。
' 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
// 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 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 VJ# code generator produces the following source code for the // preceeding example code: // this.add_TestEvent(new System.EventHandler(this.TestMethod));

System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeAttachEventStatement


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CodeAttachEventStatement クラスのページへのリンク