Hi Lance,
I think you may also try to inherits the GetProperties and
GetPropertiesSupported method.
Here is some code for your reference.
NOTE: the code has not been detailed tested, you may need to change
according to your scenario.
Thanks!
BTW:
For designtime issue, we have a specified newsgroup as below.
microsoft.public.dotnet.framework.windowsforms.des igntime
Dim pt As New PointF(1.1F, 2.2F)
<TypeConverter(GetType(PointFConverter))> _
Public ReadOnly Property TestPt() As PointF
Get
Return pt
End Get
End Property
End Class
Public Class PointFConverter
Inherits ExpandableObjectConverter
' Methods
Public Sub New()
End Sub
Public Overloads Function CanConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
If (sourceType Is GetType(String)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Function CanConvertTo(ByVal context As
ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
If (destinationType Is GetType(InstanceDescriptor)) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overloads Function ConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object) As Object
If Not TypeOf value Is String Then
Return MyBase.ConvertFrom(context, culture, value)
End If
Dim text1 As String = CType(value, String).Trim
If (text1.Length = 0) Then
Return Nothing
End If
If (culture Is Nothing) Then
culture = CultureInfo.CurrentCulture
End If
Dim ch1 As Char = culture.TextInfo.ListSeparator.Chars(0)
Dim chArray1 As Char() = New Char() {ch1}
Dim textArray1 As String() = text1.Split(chArray1)
Dim numArray1 As Single() = New Single(textArray1.Length - 1) {}
Dim converter1 As TypeConverter =
TypeDescriptor.GetConverter(GetType(Integer))
Dim num1 As Single
For num1 = 0 To numArray1.Length - 1
numArray1(num1) = CType(converter1.ConvertFromString(context,
culture, textArray1(num1)), Integer)
Next num1
If (numArray1.Length = 2) Then
Return New PointF(numArray1(0), numArray1(1))
End If
Dim objArray1 As Object() = New Object() {text1, "x, y"}
End Function
Public Overloads Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object, ByVal destinationType As Type) As Object
If (destinationType Is Nothing) Then
Throw New ArgumentNullException("destinationType")
End If
If ((destinationType Is GetType(String)) AndAlso TypeOf value Is
PointF) Then
Dim point1 As PointF = CType(value, PointF)
If (culture Is Nothing) Then
culture = CultureInfo.CurrentCulture
End If
Dim text1 As String = (culture.TextInfo.ListSeparator & " ")
Dim converter1 As TypeConverter =
TypeDescriptor.GetConverter(GetType(Single))
Dim textArray1 As String() = New String(2 - 1) {}
Dim num1 As Single = 0
textArray1(num1) = converter1.ConvertToString(context, culture,
point1.X)
num1 += 1
textArray1(num1) = converter1.ConvertToString(context, culture,
point1.Y)
Return String.Join(text1, textArray1)
End If
If ((destinationType Is GetType(InstanceDescriptor)) AndAlso TypeOf
value Is Point) Then
Dim point2 As Point = CType(value, Point)
Dim typeArray1 As Type() = New Type() {GetType(Integer),
GetType(Integer)}
Dim info1 As ConstructorInfo =
GetType(Point).GetConstructor(typeArray1)
If (Not info1 Is Nothing) Then
Dim objArray1 As Object() = New Object() {point2.X,
point2.Y}
Return New InstanceDescriptor(info1, objArray1)
End If
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Function GetProperties(ByVal context As
ITypeDescriptorContext, ByVal value As Object, ByVal attributes As
Attribute()) As PropertyDescriptorCollection
Dim collection1 As PropertyDescriptorCollection =
TypeDescriptor.GetProperties(GetType(PointF), attributes)
Dim textArray1 As String() = New String() {"X", "Y"}
Return collection1.Sort(textArray1)
End Function
Public Overloads Function GetPropertiesSupported(ByVal context As
ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.