Type.GetEvent メソッド
現在の Type で宣言または継承されている特定のイベントを取得します。
オーバーロードの一覧
指定したイベントを表す EventInfo オブジェクトを返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Function GetEvent(String) As EventInfo
派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、指定したイベントを表す EventInfo オブジェクトを返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public MustOverride Function GetEvent(String, BindingFlags) As EventInfo
[C#] public abstract EventInfo GetEvent(string, BindingFlags);
[C++] public: virtual EventInfo* GetEvent(String*, BindingFlags) = 0;
[JScript] public abstract function GetEvent(String, BindingFlags) : EventInfo;
使用例
[Visual Basic, C#, C++] メモ ここでは、GetEvent のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
Imports System.Reflection
Imports System.Security
Imports Microsoft.VisualBasic
' Compile this sample using the following command line:
' vbc type_getevent.vb /r:"System.Windows.Forms.dll" /r:"System.dll"
Class MyEventExample
Public Shared Sub Main()
Try
' Creates a bitmask comprising BindingFlags.
Dim myBindingFlags As BindingFlags = BindingFlags.Instance Or BindingFlags.Public _
Or BindingFlags.NonPublic
Dim myTypeBindingFlags As Type = GetType(System.Windows.Forms.Button)
Dim myEventBindingFlags As EventInfo = myTypeBindingFlags.GetEvent("Click", myBindingFlags)
If Not (myEventBindingFlags Is Nothing) Then
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.")
Console.WriteLine(myEventBindingFlags.ToString())
Else
Console.WriteLine("The Click event is not available with the Button class.")
End If
Catch e As SecurityException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As ArgumentNullException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message)
End Try
End Sub 'Main
End Class 'MyEventExample
[C#]
using System;
using System.Reflection;
using System.Security;
class MyEventExample
{
public static void Main()
{
try
{
// Creates a bitmask based on BindingFlags.
BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags);
if(myEventBindingFlags != null)
{
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
Console.WriteLine(myEventBindingFlags.ToString());
}
else
Console.WriteLine("The Click event is not available with the Button class.");
}
catch(SecurityException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Security;
using namespace System::Windows::Forms;
int main() {
try {
// Creates a bitmask based on BindingFlags.
BindingFlags myBindingFlags = static_cast<BindingFlags>(BindingFlags::Instance | BindingFlags::Public | BindingFlags::NonPublic);
Type* myTypeBindingFlags = __typeof(System::Windows::Forms::Button);
EventInfo* myEventBindingFlags = myTypeBindingFlags->GetEvent(S"Click", myBindingFlags);
if (myEventBindingFlags != 0) {
Console::WriteLine(S"Looking for the Click event in the Button class with the specified BindingFlags.");
Console::WriteLine(myEventBindingFlags);
} else
Console::WriteLine(S"The Click event is not available with the Button class.");
} catch (SecurityException* e) {
Console::WriteLine(S"An exception occurred.");
Console::WriteLine(S"Message : {0}", e->Message);
} catch (ArgumentNullException* e) {
Console::WriteLine(S"An exception occurred.");
Console::WriteLine(S"Message : {0}", e->Message);
} catch (Exception* e) {
Console::WriteLine(S"The following exception was raised : {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。