Hi everyone, I have a UserControl that I want to show some of its properties whit the percentage char like (100%) so I created a class that inherits from TypeConverter class. For some reason it doesn’t work see the image. What could be the problem?
Thanks in advance!
Here is the class:
and this is how i use it:vb Code:
Public Class PercentageConverter Inherits TypeConverter Public Sub New() End Sub Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean If sourceType Is GetType(String) Then Return True End If Return MyBase.CanConvertFrom(context, sourceType) End Function Public Overloads 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 Dim s As String s = CStr(value) If s.EndsWith("%") Then s = (CStr(value)).Substring(0, (CStr(value)).Length - 1) End If Return Double.Parse(s, NumberStyles.Any, culture) / 100 End If Return MyBase.ConvertFrom(context, culture, value) End Function Public Overloads 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 Dim v As Double v = CDbl(value) * 100 Return CStr(v) & "%" End If Return MyBase.ConvertTo(context, culture, value, destinationType) End Function End Class
vb Code:
''' <summary> ''' Gets or sets the size of the center-point that is directly proportional to the circumference of the clock. ''' </summary> <DefaultValue(0.03R), TypeConverterAttribute(GetType(PercentageConverter)), _ Bindable(True), Category("Layout"), Description( _ "Indicates the size of the center-point that is directly proportional to the circumference of the clock.")> _ Public Property CenterPointSize() As Double '<DebuggerHidden()> _ Get Return Me._centerPointRatio End Get '<DebuggerHidden()> _ Set(ByVal value As Double) If Not Me._centerPointRatio.Equals(value) Then If value < 0 Or value > 1 Then Throw New Exception("The value should be in the range of 0 to 100.") Else Me._centerPointRatio = value Me.SetCenterPointPath() Me.ClockPanel.Invalidate() Me.ClockPanel.Update() End If End If End Set End Property




Reply With Quote