FontConverter 类

定义

Font 对象从一种数据类型转换为另一种数据类型。

public ref class FontConverter : System::ComponentModel::TypeConverter
public class FontConverter : System.ComponentModel.TypeConverter
type FontConverter = class
    inherit TypeConverter
Public Class FontConverter
Inherits TypeConverter
继承
FontConverter

示例

下面的代码示例演示如何使用 FontConverter 字符串转换到字符串和从字符串转换 Font 。 此示例旨在与 Windows 窗体一起使用。 将此代码粘贴到窗体中,并在处理表单ShowFontStringConversion的事件时调用Paint该方法,并传递 e 作为 PaintEventArgs

void ShowFontStringConversion( PaintEventArgs^ e )
{
   // Create the FontConverter.
   System::ComponentModel::TypeConverter^ converter =
         System::ComponentModel::TypeDescriptor::GetConverter( System::Drawing::Font::typeid );
   System::Drawing::Font^ font1 = dynamic_cast<System::Drawing::Font^>(converter->ConvertFromString( "Arial, 12pt" ));
   String^ fontName1 = converter->ConvertToInvariantString( font1 );
   String^ fontName2 = converter->ConvertToString( font1 );
   e->Graphics->DrawString( fontName1, font1, Brushes::Red, 10, 10 );
   e->Graphics->DrawString( fontName2, font1, Brushes::Blue, 10, 30 );
}
private void ShowFontStringConversion(PaintEventArgs e)
{

    // Create the FontConverter.
    System.ComponentModel.TypeConverter converter = 
        System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font));

    Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");

    string fontName1 = converter.ConvertToInvariantString(font1);
    string fontName2 = converter.ConvertToString(font1);

    e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10);
    e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30);
}
Private Sub ShowFontStringConversion(ByVal e As PaintEventArgs)

    ' Create the FontConverter.
    Dim converter As System.ComponentModel.TypeConverter = _
        System.ComponentModel.TypeDescriptor.GetConverter(GetType(Font))

    Dim font1 As Font = _
        CType(converter.ConvertFromString("Arial, 12pt"), Font)

    Dim fontName1 As String = _
        converter.ConvertToInvariantString(font1)
    Dim fontName2 As String = converter.ConvertToString(font1)

    e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10)
    e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30)
End Sub

注解

类型转换器用于在数据类型之间转换值。 类型转换器还通过提供文本到值转换或用户可以从中选择的值列表,在设计时还支持属性配置。 FontConverter通过调用TypeDescriptor该方法通过GetConverter类访问类。

注释

在 .NET 6 及更高版本中,包含此类型的 System.Drawing.Common 包 仅支持在 Windows 操作系统上运行。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 仅在 Windows 上支持的 System.Drawing.Common。

构造函数

名称 说明
FontConverter()

初始化新 FontConverter 对象。

方法

名称 说明
CanConvertFrom(ITypeDescriptorContext, Type)

确定此转换器是否可以将指定源类型中的对象转换为转换器的本机类型。

CanConvertFrom(Type)

返回此转换器是否可以将给定类型的对象转换为此转换器的类型。

(继承自 TypeConverter)
CanConvertTo(ITypeDescriptorContext, Type)

获取一个值,该值指示此转换器是否可以使用上下文将对象转换为给定的目标类型。

CanConvertTo(Type)

返回此转换器是否可以将对象转换为指定类型。

(继承自 TypeConverter)
ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

将指定的对象转换为转换器的本机类型。

ConvertFrom(Object)

将给定值转换为此转换器的类型。

(继承自 TypeConverter)
ConvertFromInvariantString(ITypeDescriptorContext, String)

使用固定区域性和指定的上下文将给定字符串转换为此转换器的类型。

(继承自 TypeConverter)
ConvertFromInvariantString(String)

使用固定区域性将给定字符串转换为此转换器的类型。

(继承自 TypeConverter)
ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

使用指定的上下文和区域性信息将给定文本转换为对象。

(继承自 TypeConverter)
ConvertFromString(ITypeDescriptorContext, String)

使用指定的上下文将给定文本转换为对象。

(继承自 TypeConverter)
ConvertFromString(String)

将指定的文本转换为对象。

(继承自 TypeConverter)
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

将指定的对象转换为另一种类型。

ConvertTo(Object, Type)

使用参数将给定值对象转换为指定类型。

(继承自 TypeConverter)
ConvertToInvariantString(ITypeDescriptorContext, Object)

使用指定的上下文将指定值转换为区域性固定字符串表示形式。

(继承自 TypeConverter)
ConvertToInvariantString(Object)

将指定的值转换为区域性固定字符串表示形式。

(继承自 TypeConverter)
ConvertToString(ITypeDescriptorContext, CultureInfo, Object)

使用指定的上下文和区域性信息将给定值转换为字符串表示形式。

(继承自 TypeConverter)
ConvertToString(ITypeDescriptorContext, Object)

使用给定上下文将给定值转换为字符串表示形式。

(继承自 TypeConverter)
ConvertToString(Object)

将指定的值转换为字符串表示形式。

(继承自 TypeConverter)
CreateInstance(IDictionary)

为对象重新创建一个 Object 给定的一组属性值。

(继承自 TypeConverter)
CreateInstance(ITypeDescriptorContext, IDictionary)

使用对象的指定属性值集创建此类型的对象。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
Finalize()

FontConverter允许在垃圾回收回收之前FontConverter尝试释放资源并执行其他清理操作。

GetConvertFromException(Object)

返回在无法执行转换时引发的异常。

(继承自 TypeConverter)
GetConvertToException(Object, Type)

返回在无法执行转换时引发的异常。

(继承自 TypeConverter)
GetCreateInstanceSupported()

返回更改此对象上的值是否需要调用 CreateInstance(IDictionary) 方法才能创建新值。

(继承自 TypeConverter)
GetCreateInstanceSupported(ITypeDescriptorContext)

确定更改此对象上的值是否应要求调用 CreateInstance 该方法来创建新值。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetProperties(ITypeDescriptorContext, Object, Attribute[])

检索此类型的属性集。 默认情况下,类型没有任何要返回的属性。

GetProperties(ITypeDescriptorContext, Object)

使用指定的上下文返回由值参数指定的数组类型的属性集合。

(继承自 TypeConverter)
GetProperties(Object)

返回由值参数指定的数组类型的属性集合。

(继承自 TypeConverter)
GetPropertiesSupported()

返回此对象是否支持属性。

(继承自 TypeConverter)
GetPropertiesSupported(ITypeDescriptorContext)

确定此对象是否支持属性。 默认值为 false

GetStandardValues()

从此类型转换器设计为数据类型的默认上下文中返回标准值的集合。

(继承自 TypeConverter)
GetStandardValues(ITypeDescriptorContext)

返回此类型转换器在提供格式上下文时设计的数据类型的标准值的集合。

(继承自 TypeConverter)
GetStandardValuesExclusive()

返回从 GetStandardValues() 返回的标准值的集合是否为独占列表。

(继承自 TypeConverter)
GetStandardValuesExclusive(ITypeDescriptorContext)

返回从 GetStandardValues() 返回的标准值的集合是否是使用指定上下文的可能值的独占列表。

(继承自 TypeConverter)
GetStandardValuesSupported()

返回此对象是否支持可从列表中选择的标准值集。

(继承自 TypeConverter)
GetStandardValuesSupported(ITypeDescriptorContext)

返回此对象是否支持使用指定上下文从列表中选取的标准值集。

(继承自 TypeConverter)
GetType()

获取当前实例的 Type

(继承自 Object)
IsValid(ITypeDescriptorContext, Object)

返回给定值对象是否对此类型和指定的上下文有效。

(继承自 TypeConverter)
IsValid(Object)

返回给定值对象是否对此类型有效。

(继承自 TypeConverter)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
SortProperties(PropertyDescriptorCollection, String[])

对属性的集合进行排序。

(继承自 TypeConverter)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅