DesignerCategoryAttribute 类

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

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=True)> _
Public NotInheritable Class DesignerCategoryAttribute
    Inherits Attribute
用法
Dim instance As DesignerCategoryAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] 
public sealed class DesignerCategoryAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=false, Inherited=true)] 
public ref class DesignerCategoryAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) */ 
public final class DesignerCategoryAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) 
public final class DesignerCategoryAttribute extends Attribute

备注

可视化设计器可以使用设计器类别通知开发环境将要实现的设计器类型。如果没有为某个类提供任何设计器类别,开发环境可能允许设计此类,也可能不允许。可以创建任何名称的类别。

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

DesignerCategoryAttribute 类定义下列通用类别:

类别

说明

组件

与组件一起使用的设计器。此属性被设置为常数成员 DesignerCategoryAttribute.Component

窗体

与窗体一起使用的设计器。此属性被设置为常数成员 DesignerCategoryAttribute.Form

设计器

与设计器一起使用的设计器。此属性被设置为常数成员 DesignerCategoryAttribute.Generic

空字符串 ("")

这是默认类别。

有关更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据

示例

下面的示例创建一个名为 MyForm 的类。MyForm 有两个属性:一个是 DesignerAttribute,用于指定此类使用 DocumentDesigner;另一个是 DesignerCategoryAttribute,用于指定 Form 类别。

<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
[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",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};
/** @attribute Designer("System.Windows.Forms.Design.DocumentDesigner, "
    + "System.Windows.Forms.Design", IRootDesigner.class)
    @attribute DesignerCategory("Form")
 */
public static class MyForm extends ContainerControl
{
    // Insert code here.
} //MyForm

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

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
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;
}
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 void main(String[] args)
{
    // 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.get_Item(DesignerCategoryAttribute.class.ToType()));

    Console.WriteLine("The category of the designer " 
        + "for this class is: " + myAttribute.get_Category());
} //main

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.DesignerCategoryAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DesignerCategoryAttribute 成员
System.ComponentModel 命名空间
Attribute
DesignerAttribute 类