DesignerAttribute Kelas

Definisi

Menentukan kelas yang digunakan untuk menerapkan layanan waktu desain untuk komponen.

public ref class DesignerAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class DesignerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)>]
type DesignerAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerAttribute
Inherits Attribute
Warisan
DesignerAttribute
Atribut

Contoh

Contoh berikut membuat kelas yang disebut MyForm. MyForm memiliki dua atribut, yang DesignerAttribute menentukan kelas ini menggunakan DocumentDesigner, dan DesignerCategoryAttribute yang menentukan Form kategori.

[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
public class MyForm : ContainerControl {
    // Insert code here.
}
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", _
    GetType(IRootDesigner)), DesignerCategory("Form")> _
Public Class MyForm
    
    Inherits ContainerControl
    ' Insert code here.
End Class

Contoh berikutnya membuat instans MyForm. Kemudian mendapatkan atribut untuk kelas , mengekstrak DesignerAttribute, dan mencetak nama desainer.

int main()
{
   // Creates a new form.
   MyForm^ myNewForm = gcnew MyForm;

   // Gets the attributes for the collection.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewForm );

   /* Prints the name of the designer by retrieving the DesignerAttribute
       * from the AttributeCollection. */
   DesignerAttribute^ myAttribute = dynamic_cast<DesignerAttribute^>(attributes[ DesignerAttribute::typeid ]);
   Console::WriteLine( "The designer for this class is: {0}", myAttribute->DesignerTypeName );
   return 0;
}
public static int Main() {
    // Creates a new form.
    MyForm myNewForm = new MyForm();
 
    // Gets the attributes for the collection.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewForm);
 
    /* Prints the name of the designer by retrieving the DesignerAttribute
     * from the AttributeCollection. */
    DesignerAttribute myAttribute = 
       (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    Console.WriteLine("The designer for this class is: " + myAttribute.DesignerTypeName);
  
    return 0;
}
Public Shared Function Main() As Integer
    ' Creates a new form.
    Dim myNewForm As New MyForm()
    
    ' Gets the attributes for the collection.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewForm)
    
    ' Prints the name of the designer by retrieving the DesignerAttribute
    ' from the AttributeCollection. 
    Dim myAttribute As DesignerAttribute = _
        CType(attributes(GetType(DesignerAttribute)), DesignerAttribute)
    Console.WriteLine(("The designer for this class is: " & myAttribute.DesignerTypeName))
    
    Return 0
End Function 'Main

Keterangan

Kelas yang Anda gunakan untuk layanan waktu desain harus mengimplementasikan IDesigner antarmuka.

DesignerBaseTypeName Gunakan properti untuk menemukan jenis dasar perancang. DesignerTypeName Gunakan properti untuk mendapatkan nama jenis perancang yang terkait dengan anggota ini.

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

DesignerAttribute(String)

Menginisialisasi instans DesignerAttribute baru kelas menggunakan nama jenis yang menyediakan layanan waktu desain.

DesignerAttribute(String, String)

Menginisialisasi instans DesignerAttribute baru kelas menggunakan jenis perancang dan kelas dasar untuk perancang.

DesignerAttribute(String, Type)

Menginisialisasi instans DesignerAttribute baru kelas, menggunakan nama kelas perancang dan kelas dasar untuk perancang.

DesignerAttribute(Type)

Menginisialisasi instans DesignerAttribute baru kelas menggunakan jenis yang menyediakan layanan waktu desain.

DesignerAttribute(Type, Type)

Menginisialisasi instans DesignerAttribute baru kelas menggunakan jenis kelas dasar perancang dan perancang.

Properti

DesignerBaseTypeName

Mendapatkan nama jenis dasar perancang ini.

DesignerTypeName

Mendapatkan nama jenis desainer yang terkait dengan atribut perancang ini.

TypeId

Mendapatkan ID unik untuk jenis atribut ini.

Metode

Equals(Object)

Mengembalikan apakah nilai objek yang diberikan sama dengan saat ini DesignerAttribute.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga