DesignerCategoryAttribute 类

定义

指定类设计器属于某一类别。

public ref class DesignerCategoryAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class DesignerCategoryAttribute : Attribute
public sealed class DesignerCategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type DesignerCategoryAttribute = class
    inherit Attribute
type DesignerCategoryAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerCategoryAttribute
Inherits Attribute
继承
DesignerCategoryAttribute
属性

示例

以下示例创建一个名为 的 MyForm类。 MyForm 具有两个属性,一个 DesignerAttribute 指定此类使用 DocumentDesigner的 ,一个 DesignerCategoryAttribute 指定类别的 Form

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

下一个示例创建 的 MyForm实例。 然后,它获取 类的属性,提取 DesignerCategoryAttribute,并打印设计器的名称。

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 
       * DesignerCategoryAttribute from the AttributeCollection. */
   DesignerCategoryAttribute^ myAttribute = dynamic_cast<DesignerCategoryAttribute^>(attributes[ DesignerCategoryAttribute::typeid ]);
   Console::WriteLine( "The category of the designer for this class is: {0}", myAttribute->Category );
   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 
     * DesignerCategoryAttribute from the AttributeCollection. */
    DesignerCategoryAttribute myAttribute = 
       (DesignerCategoryAttribute)attributes[typeof(DesignerCategoryAttribute)];
    Console.WriteLine("The category of the designer for this class is: " + myAttribute.Category);
  
    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
    ' DesignerCategoryAttribute from the AttributeCollection. 
    Dim myAttribute As DesignerCategoryAttribute = _
        CType(attributes(GetType(DesignerCategoryAttribute)), DesignerCategoryAttribute)
    Console.WriteLine(("The category of the designer for this class is: " + myAttribute.Category))
    Return 0
End Function 'Main

注解

可视化设计器可以使用设计器类别来通知开发环境将要实现的设计器类型。 如果未在类上提供设计器类别,则开发环境可能允许或不允许设计类。 可以为任何名称创建类别。

使用此属性标记类时,该类将设置为常量成员。 如果要在代码中检查此属性的值,则必须指定常量成员。 下表中的“说明”列列出了每个值设置为的常量成员。

DesignerCategoryAttribute 定义以下常见类别:

类别 说明
组件 与组件一起使用的设计器。 属性设置为常量成员 DesignerCategoryAttribute.Component
窗体 与窗体一起使用的设计器。 属性设置为常量成员 DesignerCategoryAttribute.Form
Designer 与设计器一起使用的设计器。 属性设置为常量成员 DesignerCategoryAttribute.Generic
空字符串 (“”) 这是默认类别。

有关更多信息,请参阅特性

构造函数

DesignerCategoryAttribute()

用空字符串 ("") 初始化 DesignerCategoryAttribute 类的新实例。

DesignerCategoryAttribute(String)

用给定的类别名称初始化 DesignerCategoryAttribute 类的新实例。

字段

Component

指定标记为此类别的组件使用组件设计器。 此字段为只读。

Default

指定标记为此类别的组件不能使用可视化设计器。 此 static 字段是只读的。

Form

指定标记为此类别的组件使用窗体设计器。 此 static 字段是只读的。

Generic

指定标记为此类别的组件使用一般设计器。 此 static 字段是只读的。

属性

Category

获取类别名称。

TypeId

获取此特性的唯一标识符。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回给定对象的值是否等于当前的 DesignOnlyAttribute

GetHashCode()

返回此实例的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

确定此特性是否为默认特性。

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)

适用于

另请参阅