Specifies the default property for a component.
For a list of all members of this type, see DefaultPropertyAttribute Members.
System.Object
System.Attribute
System.ComponentModel.DefaultPropertyAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.Class)> NotInheritable Public Class DefaultPropertyAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.Class)] public sealed class DefaultPropertyAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::Class)] public __gc __sealed class DefaultPropertyAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.Class) class DefaultPropertyAttribute extends Attribute
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Use the Name property to get the name of the default event.
For more information, see
[Visual Basic, C#] The following example defines a control named MyControl. The class is marked with a DefaultPropertyAttribute that specifies MyProperty as the default property.
[Visual Basic] <DefaultProperty("MyProperty")> _ Public Class MyControl Inherits Control Public Property MyProperty() As Integer Get ' Insert code here. Return 0 End Get Set ' Insert code here. End Set End Property ' Insert any additional code. End Class 'MyControl [C#] [DefaultProperty("MyProperty")] public class MyControl : Control { public int MyProperty { get { // Insert code here. return 0; } set { // Insert code here. } } // Insert any additional code. }
[Visual Basic, C#] The next example creates an instance of MyControl. Then it gets the attributes for the class, extracts the DefaultPropertyAttribute, and prints the name of the default property.
[Visual Basic] Public Shared Function Main() As Integer ' Creates a new control. Dim myNewControl As New MyControl() ' Gets the attributes for the collection. Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewControl) ' Prints the name of the default property by retrieving the ' DefaultPropertyAttribute from the AttributeCollection. Dim myAttribute As DefaultPropertyAttribute = _ CType(attributes(GetType(DefaultPropertyAttribute)), DefaultPropertyAttribute) Console.WriteLine(("The default property is: " + myAttribute.Name)) Return 0 End Function 'Main [C#] public static int Main() { // Creates a new control. MyControl myNewControl = new MyControl(); // Gets the attributes for the collection. AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl); /* Prints the name of the default property by retrieving the * DefaultPropertyAttribute from the AttributeCollection. */ DefaultPropertyAttribute myAttribute = (DefaultPropertyAttribute)attributes[typeof(DefaultPropertyAttribute)]; Console.WriteLine("The default property is: " + myAttribute.Name); return 0; }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.ComponentModel
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
DefaultPropertyAttribute Members | System.ComponentModel Namespace | Attribute