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

<AttributeUsageAttribute(AttributeTargets.Class)> _ Public NotInheritable Class DefaultEventAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class)] public sealed class DefaultEventAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class)] public ref class DefaultEventAttribute sealed : public Attribute


MyCollection という名前のコレクション クラスを定義する例を次に示します。このクラスは、既定のイベントとして CollectionChanged を指定する DefaultEventAttribute を使用してマークされます。
<DefaultEvent("CollectionChanged")> _ Public Class MyCollection Inherits BaseCollection Public Event CollectionChanged (ByVal sender As Object, _ ByVal e As CollectionChangeEventArgs) ' Insert additional code. End Class 'MyCollection
[DefaultEvent("CollectionChanged")] public class MyCollection : BaseCollection { private CollectionChangeEventHandler onCollectionChanged; public event CollectionChangeEventHandler CollectionChanged { add { onCollectionChanged += value; } remove { onCollectionChanged -= value; } } // Insert additional code. }
[DefaultEvent("CollectionChanged")] public ref class TestCollection: public BaseCollection { private: CollectionChangeEventHandler^ onCollectionChanged; public: event CollectionChangeEventHandler^ CollectionChanged { public: void add(CollectionChangeEventHandler^ eventHandler) { onCollectionChanged += eventHandler; } protected: void remove(CollectionChangeEventHandler^ eventHandler) { onCollectionChanged -= eventHandler; } } // Insert additional code. };
/** @attribute DefaultEvent("CollectionChanged") */ public static class MyCollection extends BaseCollection { private CollectionChangeEventHandler onCollectionChanged; public void add_onCollectionChanged(CollectionChangeEventHandler value) { onCollectionChanged = (CollectionChangeEventHandler) System.Delegate.Combine(onCollectionChanged, value); } public void remove_onCollectionChanged(CollectionChangeEventHandler value) { onCollectionChanged = (CollectionChangeEventHandler) System.Delegate.Remove(onCollectionChanged, value); } // Insert additional code. } //MyCollection
MyCollection のインスタンスを作成する例を次に示します。そのクラスの属性を取得し、DefaultEventAttribute を抽出してから、既定のイベントの名前を出力します。
Public Shared Function Main() As Integer ' Creates a new collection. Dim myNewCollection As New MyCollection() ' Gets the attributes for the collection. Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewCollection) ' Prints the name of the default event by retrieving the ' DefaultEventAttribute from the AttributeCollection. Dim myAttribute As DefaultEventAttribute = _ CType(attributes(GetType(DefaultEventAttribute)), DefaultEventAttribute) Console.WriteLine(("The default event is: " & myAttribute.Name)) Return 0 End Function 'Main
public static int Main() { // Creates a new collection. MyCollection myNewCollection = new MyCollection(); // Gets the attributes for the collection. AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewCollection); /* Prints the name of the default event by retrieving the * DefaultEventAttribute from the AttributeCollection. */ DefaultEventAttribute myAttribute = (DefaultEventAttribute)attributes[typeof(DefaultEventAttribute)]; Console.WriteLine("The default event is: " + myAttribute.Name); return 0; }
int main() { // Creates a new collection. DefaultEventAttributeExample::TestCollection^ newCollection = gcnew DefaultEventAttributeExample::TestCollection; // Gets the attributes for the collection. AttributeCollection^ attributes = TypeDescriptor::GetAttributes(newCollection); // Prints the name of the default event by retrieving the // DefaultEventAttribute from the AttributeCollection. DefaultEventAttribute^ attribute = (DefaultEventAttribute^) attributes[DefaultEventAttribute::typeid]; Console::WriteLine("The default event is: {0}", attribute->Name); }
public static void main(String[] args) { // Creates a new collection. MyCollection myNewCollection = new MyCollection(); // Gets the attributes for the collection. AttributeCollection attributes = TypeDescriptor. GetAttributes(myNewCollection); /* Prints the name of the default event by retrieving the * DefaultEventAttribute from the AttributeCollection. */ DefaultEventAttribute myAttribute = (DefaultEventAttribute)attributes. get_Item(DefaultEventAttribute.class.ToType()); Console.WriteLine("The default event is: " + myAttribute.get_Name()); } //main

System.Attribute
System.ComponentModel.DefaultEventAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDefaultEventAttribute クラスを検索する場合は、下記のリンクをクリックしてください。

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