Public Class FontFamilyConverter
Inherits TypeConverter
Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
Return (sourceType Is GetType(String))
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
Return (destinationType Is GetType(String))
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
Dim obj As String = DirectCast(value, String)
If obj IsNot Nothing AndAlso obj.Length > 0 Then
Return New FontFamily(obj)
Else
Return New FontFamily("Verdana")
End If
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
If value IsNot Nothing Then
Dim ff As FontFamily = DirectCast(value, FontFamily)
Return ff.ToString()
End If
Return Nothing
End Function
End Class