DefaultEventAttribute Třída

Definice

Určuje výchozí událost pro komponentu.

public ref class DefaultEventAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class DefaultEventAttribute : Attribute
public sealed class DefaultEventAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type DefaultEventAttribute = class
    inherit Attribute
type DefaultEventAttribute = class
    inherit Attribute
Public NotInheritable Class DefaultEventAttribute
Inherits Attribute
Dědičnost
DefaultEventAttribute
Atributy

Příklady

Následující příklad definuje třídu kolekce s názvem MyCollection. Třída je označena DefaultEventAttributeCollectionChanged jako výchozí událost.

[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.
};
[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 Class MyCollection
    Inherits BaseCollection

    Public Event CollectionChanged (ByVal sender As Object, _
        ByVal e As CollectionChangeEventArgs)
    
    ' Insert additional code.
End Class

Další příklad vytvoří instanci objektu MyCollection. Pak získá atributy pro třídu, extrahuje DefaultEventAttributea vytiskne název výchozí události.

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 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;
 }
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

Poznámky

Name Pomocí vlastnosti získejte název výchozí události.

Další informace najdete v tématu Atributy.

Konstruktory

DefaultEventAttribute(String)

Inicializuje novou instanci DefaultEventAttribute třídy.

Pole

Default

Určuje výchozí hodnotu pro DefaultEventAttribute, což je null. Toto static pole je jen pro čtení.

Vlastnosti

Name

Získá název výchozí události pro komponentu, na které je tento atribut vázán.

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tuto Attributetřídu .

(Zděděno od Attribute)

Metody

Equals(Object)

Vrátí, zda je hodnota daného objektu rovna aktuálnímu DefaultEventAttributeobjektu .

GetHashCode()

Vrátí hodnotu hash pro tuto instanci.

GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
IsDefaultAttribute()

Při přepsání v odvozené třídě označuje, zda je hodnota této instance výchozí hodnotou pro odvozenou třídu.

(Zděděno od Attribute)
Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, které lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také