我需要实现一个TypeConverter来强制支持的GetStandardValuesSupported返回false。
然后我就可以去掉颜色属性,直接使用。
<CategoryAttribute("Order Colour"), _
Browsable(True), _
DisplayName("Custom Colour to Use"), _
Description("The background colour for orders from this terminal"), _
EditorAttribute(GetType(IKMDependency.ColourSelectorEditor), GetType(System.Drawing.Design.UITypeEditor)), _
TypeConverter(GetType(ColourTypeConverter))> _
Public Property Colour() As Color
Get
Return mColor
End Get
Set(ByVal value As Color)
If mColor <> value Then
mColor = value
mIsDirty = True
End If
End Set
End Property
这有点难看,因为框中的颜色表示为所选的颜色,但文本打印在PropertyGridCell的其余部分中,因此我还向转换器添加了一些重写以仅返回空字符串。(我宁愿把整个牢房都涂成这种颜色,而不仅仅是小盒子)。
转换器类。
Public Class ColourTypeConverter
Inherits TypeConverter
Public Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return False
End Function
Public Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If sourceType Is GetType(String) Then Return False
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
If destinationType Is GetType(String) Then Return String.Empty
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
Return MyBase.ConvertFrom(context, culture, value)
End Function
Public Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
If destinationType Is GetType(String) Then Return False
Return MyBase.CanConvertTo(context, destinationType)
End Function
End Class