[Visual Basic]
<Description("The image associated with the control"), _
Category("Appearance")> _
Public Property MyImage() As Image
Get
' Insert code here.
Return image1
End Get
Set
' Insert code here.
End Set
End Property
[C#]
[Description("The image associated with the control"),Category("Appearance")]
public Image MyImage {
get {
// Insert code here.
return image1;
}
set {
// Insert code here.
}
}
[Visual Basic, C#] 下一个示例获取 MyImage 的说明。首先,代码获取具有该对象的所有属性的 PropertyDescriptorCollection。接着,它对 PropertyDescriptorCollection 进行索引以获取 MyImage。然后它返回该属性的特性,并将它们保存到特性变量中。
[Visual Basic]
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
TypeDescriptor.GetProperties(Me)("MyImage").Attributes
' Prints the description by retrieving the DescriptionAttribute
' from the AttributeCollection.
Dim myAttribute As DescriptionAttribute = _
CType(attributes(GetType(DescriptionAttribute)), DescriptionAttribute)
Console.WriteLine(myAttribute.Description)
[C#]
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyImage"].Attributes;
/* Prints the description by retrieving the DescriptionAttribute
* from the AttributeCollection. */
DescriptionAttribute myAttribute =
(DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
Console.WriteLine(myAttribute.Description);
[Description("设置在注册表启动项中键名的属性")]
public string RegName
{
get
{return regName;}
set
{regName=value;}
}
F:\projects\StartWithReg\StartWithComputer.cs(72): 找不到类型或命名空间名称“Description”(是否缺少 using 指令或程序集引用?)
怎么会这样呢.大家给我说清楚点,好吗?
最好能帧出代码来.谢谢了