Поделиться через


DesignerAttribute Класс

Определение

Задает класс, используемый для реализации служб времени разработки для компонента.

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
Наследование
DesignerAttribute
Атрибуты

Примеры

В следующем примере создается класс с именем MyForm. MyForm имеет два атрибута, то есть, DesignerAttribute указывающее этот класс, использует DocumentDesignerэтот класс и указывает DesignerCategoryAttribute категорию Form .

[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

В следующем примере создается экземпляр MyForm. Затем он получает атрибуты для класса, извлекает DesignerAttributeи выводит имя конструктора.

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();

    // 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

Комментарии

Класс, используемый для служб времени разработки, должен реализовать IDesigner интерфейс.

DesignerBaseTypeName Используйте свойство, чтобы найти базовый тип конструктора. DesignerTypeName Используйте свойство, чтобы получить имя типа конструктора, связанного с этим элементом.

Дополнительные сведения см. в разделе Атрибуты.

Конструкторы

Имя Описание
DesignerAttribute(String, String)

Инициализирует новый экземпляр класса с помощью типа конструктора DesignerAttribute и базового класса для конструктора.

DesignerAttribute(String, Type)

Инициализирует новый экземпляр DesignerAttribute класса, используя имя класса конструктора и базовый класс для конструктора.

DesignerAttribute(String)

Инициализирует новый экземпляр DesignerAttribute класса с помощью имени типа, предоставляющего службы времени разработки.

DesignerAttribute(Type, Type)

Инициализирует новый экземпляр DesignerAttribute класса с помощью типов базового класса конструктора и конструктора.

DesignerAttribute(Type)

Инициализирует новый экземпляр DesignerAttribute класса с помощью типа, предоставляющего службы времени разработки.

Свойства

Имя Описание
DesignerBaseTypeName

Возвращает имя базового типа этого конструктора.

DesignerTypeName

Возвращает имя типа конструктора, связанного с этим атрибутом конструктора.

TypeId

Возвращает уникальный идентификатор для этого типа атрибута.

Методы

Имя Описание
Equals(Object)

Возвращает значение, равное ли заданному объекту текущее DesignerAttributeзначение.

GetHashCode()

Возвращает хэш-код для этого экземпляра.

GetType()

Возвращает Type текущего экземпляра.

(Унаследовано от Object)
IsDefaultAttribute()

При переопределении в производном классе указывает, является ли значение этого экземпляра значением по умолчанию для производного класса.

(Унаследовано от Attribute)
Match(Object)

При переопределении в производном классе возвращает значение, указывающее, равен ли этот экземпляр указанному объекту.

(Унаследовано от Attribute)
MemberwiseClone()

Создает неглубокую копию текущей Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Явные реализации интерфейса

Имя Описание
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Сопоставляет набор имен соответствующему набору идентификаторов диспетчеризации.

(Унаследовано от Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Извлекает сведения о типе объекта, который можно использовать для получения сведений о типе для интерфейса.

(Унаследовано от Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Возвращает количество предоставляемых объектом интерфейсов для доступа к сведениям о типе (0 или 1).

(Унаследовано от Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Предоставляет доступ к свойствам и методам, предоставляемым объектом.

(Унаследовано от Attribute)

Применяется к

См. также раздел