DefaultPropertyAttribute Class
.NET Framework 2.0
Specifies the default property for a component.
Namespace: System.ComponentModel
Assembly: System (in system.dll)
Assembly: System (in system.dll)
'Declaration <AttributeUsageAttribute(AttributeTargets.Class)> _ Public NotInheritable Class DefaultPropertyAttribute Inherits Attribute 'Usage Dim instance As DefaultPropertyAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ public final class DefaultPropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) public final class DefaultPropertyAttribute extends Attribute
Not applicable.
Use the Name property to get the name of the default property.
For more information, see Attributes Overview and Extending Metadata Using Attributes.
| Topic | Location |
|---|---|
| Developing Custom Data-Bound Web Server Controls for ASP.NET 1.1 | Authoring ASP.NET Controls |
| Walkthrough: Developing and Using a Custom Server Control | Authoring ASP.NET Controls |
| Developing Custom Data-Bound Web Server Controls for ASP.NET 2.0 | Authoring ASP.NET Controls |
| Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 2.0 | Authoring ASP.NET Controls |
| Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1 | Authoring ASP.NET Controls |
| Walkthrough: Developing and Using a Custom Server Control | Authoring ASP.NET Controls |
| Developing Custom Data-Bound Web Server Controls for ASP.NET 1.1 | Authoring ASP.NET Controls |
| Developing Custom Data-Bound Web Server Controls for ASP.NET 2.0 | Authoring ASP.NET Controls |
| Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 2.0 | Authoring ASP.NET Controls |
| Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1 | Authoring ASP.NET Controls |
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
/** @attribute DefaultProperty("MyProperty")
*/
public static class MyControl extends Control
{
/** @property
*/
public int get_MyProperty()
{
// Insert code here.
return 0;
} //get_MyProperty
/** @property
*/
public void set_MyProperty(int value)
{
// Insert code here.
} //set_MyProperty
// Insert any additional code.
} //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
public static void main(String[] args)
{
// 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.get_Item(
DefaultPropertyAttribute.class.ToType()));
Console.WriteLine("The default property is: "
+ myAttribute.get_Name());
} //main
Windows 98, Windows Server 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
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: