here's how:
vb Code:
Imports System.ComponentModel
Public Class UserControl1
Private _color As Color
<TypeConverter(GetType(colorConverter))> _
Public Property Color() As Color
Get
Return _color
End Get
Set(ByVal value As Color)
_color = value
End Set
End Property
End Class
uses a typeconverter class:
vb Code:
Imports System.ComponentModel
Public Class colorConverter
Inherits TypeConverter
Public Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
Return sourceType Is GetType(String)
End Function
Public Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
If TypeOf value Is String Then
Return Color.FromName(value.ToString)
End If
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
Return destinationType Is GetType(Color)
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 TypeOf value Is Color Then
Return DirectCast(value, Color).Name
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
End Class