イベント ハンドラのデリゲートをイベントに結び付けるステートメントを表します。
名前空間: System.CodeDom
アセンブリ: System (system.dll 内)
構文
'宣言
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeAttachEventStatement
Inherits CodeStatement
'使用
Dim instance As CodeAttachEventStatement
[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class CodeAttachEventStatement : CodeStatement
[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class CodeAttachEventStatement : public CodeStatement
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class CodeAttachEventStatement extends CodeStatement
SerializableAttribute
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class CodeAttachEventStatement extends 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.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeAttachEventStatement
スレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0