语言

PointConverter 类

定义

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

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

示例

下面的代码示例演示如何使用 PointConverter 和 Subtraction 运算符。 此示例旨在与 Windows 窗体一起使用。 将此代码粘贴到窗体中,并在处理表单ShowPointConverter的事件时调用Paint该方法,并传递e为 PaintEventArgs 。

void ShowPointConverter( PaintEventArgs^ e )
{
   // Create the PointConverter.
   System::ComponentModel::TypeConverter^ converter = System::ComponentModel::TypeDescriptor::GetConverter( Point::typeid );
   Point point1 =  *dynamic_cast<Point^>(converter->ConvertFromString( "200, 200" ));

   // Use the subtraction operator to get a second point.
   Point point2 = point1 - System::Drawing::Size( 190, 190 );

   // Draw a line between the two points.
   e->Graphics->DrawLine( Pens::Black, point1, point2 );
}
private void ShowPointConverter(PaintEventArgs e)
{

    // Create the PointConverter.
    System.ComponentModel.TypeConverter converter = 
        System.ComponentModel.TypeDescriptor.GetConverter(typeof(Point));

    Point point1 = (Point) converter.ConvertFromString("200, 200");

    // Use the subtraction operator to get a second point.
    Point point2 = point1 - new Size(190, 190);

    // Draw a line between the two points.
    e.Graphics.DrawLine(Pens.Black, point1, point2);
}
Private Sub ShowPointConverter(ByVal e As PaintEventArgs)

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

    Dim point1 As Point = _
        CType(converter.ConvertFromString("200, 200"), Point)

    ' Use the subtraction operator to get a second point.
    Dim point2 As Point = Point.op_Subtraction(point1, _
        New Size(190, 190))

    ' Draw a line between the two points.
    e.Graphics.DrawLine(Pens.Black, point1, point2)
End Sub

注解

该 PointConverter 类通常用于为具有类型 Point属性的控件创建设计时体验,并用于将指向转换为在设计器中显示的字符串,以及将设计器 Point 中输入的字符串转换为对象。 通过 TypeDescriptor 对象访问此类。

构造函数

名称 说明
PointConverter()

初始化 PointConverter 类的新实例。

方法

名称 说明
CanConvertFrom(ITypeDescriptorContext, Type)

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

CanConvertFrom(Type)

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

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

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

CanConvertTo(Type)

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

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

将指定的对象转换为对象 Point 。

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)
GetConvertFromException(Object)

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

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

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

(继承自 TypeConverter)
GetCreateInstanceSupported()

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

(继承自 TypeConverter)
GetCreateInstanceSupported(ITypeDescriptorContext)

确定更改此对象上的值是否需要调用 CreateInstance(ITypeDescriptorContext, IDictionary) 才能创建新值。

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)

适用于