Sdílet prostřednictvím


DefaultEventAttribute Třída

Definice

Určuje výchozí událost komponenty.

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
{
    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 MyCollection. Potom 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();

    // 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ískáte název výchozí události.

Další informace naleznete v tématu Atributy.

Konstruktory

Name Description
DefaultEventAttribute(String)

Inicializuje novou instanci DefaultEventAttribute třídy.

Pole

Name Description
Default

Určuje výchozí hodnotu pro DefaultEventAttributehodnotu , která je null. Toto static pole je jen pro čtení.

Vlastnosti

Name Description
Name

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

TypeId

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

(Zděděno od Attribute)

Metody

Name Description
Equals(Object)

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

GetHashCode()

Vrátí kód hash pro tuto instanci.

GetType()

Získá Type aktuální instance.

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

Při přepsání v odvozené třídě určuje, zda hodnota této instance je 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á určuje, zda se tato instance rovná zadanému objektu.

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

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

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

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

(Zděděno od Object)

Explicitní implementace rozhraní

Name Description
_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é