PointConverter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 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 運算 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 存取此類別。
建構函式
| 名稱 | Description |
|---|---|
| PointConverter() |
初始化 PointConverter 類別的新執行個體。 |