This documentation is archived and is not being maintained.

DefaultPropertyAttribute Class

Specifies the default property for a component.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

'Declaration
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public NotInheritable Class DefaultPropertyAttribute _
	Inherits Attribute
'Usage
Dim instance As DefaultPropertyAttribute

The following example defines a control named MyControl. The class is marked with a DefaultPropertyAttribute that specifies MyProperty as the default property.

<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

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.

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

System.Object
  System.Attribute
    System.ComponentModel.DefaultPropertyAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: