DefaultPropertyAttribute 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定元件的預設屬性。
public ref class DefaultPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class DefaultPropertyAttribute : Attribute
public sealed class DefaultPropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type DefaultPropertyAttribute = class
inherit Attribute
type DefaultPropertyAttribute = class
inherit Attribute
Public NotInheritable Class DefaultPropertyAttribute
Inherits Attribute
- 繼承
- 屬性
下列範例會定義名為 的 MyControl
控件。 類別會以 DefaultPropertyAttribute 指定 MyProperty
為預設屬性的標記。
[DefaultProperty("MyProperty")]
ref class MyControl: public Control
{
public:
property int MyProperty
{
int get()
{
// Insert code here.
return 0;
}
void set( int value )
{
// Insert code here.
}
}
// Insert any additional code.
};
[DefaultProperty("MyProperty")]
public class MyControl : Control {
public int MyProperty {
get {
// Insert code here.
return 0;
}
set {
// Insert code here.
}
}
// Insert any additional code.
}
<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
實例。 然後,它會取得 類別的屬性、擷取 DefaultPropertyAttribute,並列印預設屬性的名稱。
int main()
{
// Creates a new control.
Form1::MyControl^ myNewControl = gcnew Form1::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 = dynamic_cast<DefaultPropertyAttribute^>(attributes[ DefaultPropertyAttribute::typeid ]);
Console::WriteLine( "The default property is: {0}", myAttribute->Name );
return 0;
}
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;
}
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
Name使用屬性來取得預設屬性的名稱。
如需詳細資訊,請參閱屬性。
Default |
初始化 DefaultPropertyAttribute 類別的新執行個體。 |
Default |
指定 DefaultPropertyAttribute 的預設值,就是 |
Name |
取得與這個屬性 (Attribute) 繫結的元件的預設屬性 (Property) 名稱。 |
Type |
在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。 (繼承來源 Attribute) |
Equals(Object) |
傳回值,表示指定的物件值是否等於目前的 DefaultPropertyAttribute。 |
Get |
傳回這個執行個體的雜湊碼。 |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。 (繼承來源 Attribute) |
Match(Object) |
在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。 (繼承來源 Attribute) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
_Attribute. |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
_Attribute. |
擷取物件的類型資訊,可以用來取得介面的類型資訊。 (繼承來源 Attribute) |
_Attribute. |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
_Attribute. |
提供物件所公開的屬性和方法的存取權。 (繼承來源 Attribute) |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |