DesignerAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定用于为组件实现设计时服务的类。
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
- 继承
- 属性
示例
以下示例创建一个名为 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 |
获取此属性类型的唯一 ID。 |
方法
| 名称 | 说明 |
|---|---|
| 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) |