Hello I am creating a User Control and wanted to have a custom object property
ImageChange
.
I google this and found this link
Getting the Most Out of the .NET Framework PropertyGrid Control[
^].
Everything seems working when I run the User Control Project, can change the property (On code or manual) and prompts its current value. But when I add the User Control to another windows form project I got an error.
Please see image[
^]. This error occurs when I try changing the
ImageChange
property and saving the project.
Below is the code
Public Class UserControl
Private _imageChange As New ImageChange
Public Property OnImageChange As ImageChange
Get
Return Me._imageChange
End Get
Set(value As ImageChange)
Me._imageChange = value
End Set
End Property
End Class
<ComponentModel.TypeConverter(GetType(ImageChangeConverter))>
Public Class ImageChange
Private _zoom As Boolean = False
Private _rotate As Boolean = False
Public Property RetainZoom As Boolean
Get
Return Me._zoom
End Get
Set(value As Boolean)
Me._zoom = value
End Set
End Property
Public Property RetainRotate As Boolean
Get
Return Me._rotate
End Get
Set(value As Boolean)
Me._rotate = value
End Set
End Property
End Class
Public Class ImageChangeConverter
Inherits ComponentModel.ExpandableObjectConverter
Public Overloads Overrides Function CanConvertTo(ByVal context As ComponentModel.ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
If (destinationType Is GetType(ImageChange)) Then Return True
Return MyBase.CanConvertFrom(context, destinationType)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As ComponentModel.ITypeDescriptorContext, ByVal culture As Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
If (destinationType Is GetType(System.String) AndAlso TypeOf value Is ImageChange) Then
Try
Dim c As ImageChange = CType(value, ImageChange)
Return "{" & c.RetainZoom & ", " & c.RetainRotate & "}"
Catch
Throw New ArgumentException
End Try
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Overrides Function CanConvertFrom(ByVal context As ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If (sourceType Is GetType(String)) Then Return True
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As ComponentModel.ITypeDescriptorContext, ByVal culture As Globalization.CultureInfo, ByVal value As Object) As Object
If (TypeOf value Is String) Then
Try
Dim arr As String() = value.ToString.Replace("{", "").Replace("}", "").Split(",")
Dim c As New ImageChange With {
.RetainZoom = Boolean.Parse(arr(0).Trim),
.RetainRotate = Boolean.Parse(arr(1).Trim)
}
Return c
Catch
Throw New ArgumentException
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
End Class
Thanks in advance.
What I have tried:
One forum said restart the IDE. I already restart even my machine and still have the error.
Still searching on google. I found this answer on a forum..
I copy the answered code and still I have the same error
ExpandableObjectConverter problems[
^]