Point 結構

定義

表示整數 X 和 Y 座標之已排序的配對,此配對會定義二維平面中的點。Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.

public value class Point : IEquatable<System::Drawing::Point>
[System.ComponentModel.TypeConverter(typeof(System.Drawing.PointConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Point : IEquatable<System.Drawing.Point>
type Point = struct
Public Structure Point
Implements IEquatable(Of Point)
繼承
屬性
實作

範例

下列程式碼範例會使用為這些類型定義的數個多載運算子, 來建立點和大小。The following code example creates points and sizes using several of the overloaded operators defined for these types. 它也會示範如何使用SystemPens類別。It also demonstrates how to use the SystemPens class.

這個範例是設計來與 Windows Forms 搭配使用。This example is designed to be used with Windows Forms. 建立包含名為Button subtractButton的表單。Create a form that contains a Button named subtractButton. 將程式碼貼入表單, 並從CreatePointsAndSizes表單的Paint事件處理方法呼叫方法, 並以e PaintEventArgs傳遞。Paste the code into the form and call the CreatePointsAndSizes method from the form's Paint event-handling method, passing e as PaintEventArgs.

void CreatePointsAndSizes( PaintEventArgs^ e )
{
   // Create the starting point.
   Point startPoint = Point(subtractButton->Size);
   
   // Use the addition operator to get the end point.
   Point endPoint = startPoint + System::Drawing::Size( 140, 150 );
   
   // Draw a line between the points.
   e->Graphics->DrawLine( SystemPens::Highlight, startPoint, endPoint );
   
   // Convert the starting point to a size and compare it to the
   // subtractButton size.  
   System::Drawing::Size buttonSize = (System::Drawing::Size)startPoint;
   if ( buttonSize == subtractButton->Size )
   {
      e->Graphics->DrawString( "The sizes are equal.", gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), Brushes::Indigo, 10.0F, 65.0F );
   }
}
private void CreatePointsAndSizes(PaintEventArgs e)
{

    // Create the starting point.
    Point startPoint = new Point(subtractButton.Size);

    // Use the addition operator to get the end point.
    Point endPoint = startPoint + new Size(140, 150);

    // Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint);

    // Convert the starting point to a size and compare it to the
    // subtractButton size.  
    Size buttonSize = (Size)startPoint;
    if (buttonSize == subtractButton.Size)

        // If the sizes are equal, tell the user.
    {
        e.Graphics.DrawString("The sizes are equal.", 
            new Font(this.Font, FontStyle.Italic), 
            Brushes.Indigo, 10.0F, 65.0F);
    }

}
Private Sub CreatePointsAndSizes(ByVal e As PaintEventArgs)

    ' Create the starting point.
    Dim startPoint As New Point(subtractButton.Size)

    ' Use the addition operator to get the end point.
    Dim endPoint As Point = Point.op_Addition(startPoint, _
        New Size(140, 150))

    ' Draw a line between the points.
    e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint)

    ' Convert the starting point to a size and compare it to the
    ' subtractButton size.  
    Dim buttonSize As Size = Point.op_Explicit(startPoint)
    If (Size.op_Equality(buttonSize, subtractButton.Size)) Then

        ' If the sizes are equal, tell the user.
        e.Graphics.DrawString("The sizes are equal.", _
            New Font(Me.Font, FontStyle.Italic), _
            Brushes.Indigo, 10.0F, 65.0F)
    End If

End Sub

備註

若要將Point轉換PointF成, 請Implicit使用。To convert a Point to a PointF, use Implicit.

建構函式

Point(Int32)

使用由整數值指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class using coordinates specified by an integer value.

Point(Int32, Int32)

使用指定的座標,初始化 Point 類別的新執行個體。Initializes a new instance of the Point class with the specified coordinates.

Point(Size)

Point 初始化 Size 類別的新執行個體。Initializes a new instance of the Point class from a Size.

欄位

Empty

表示 Point,其 X 值與 Y 值設為零。Represents a Point that has X and Y values set to zero.

屬性

IsEmpty

取得值,指出這個 Point 是否為空的。Gets a value indicating whether this Point is empty.

X

取得或設定這個 Point 的 X 座標。Gets or sets the x-coordinate of this Point.

Y

取得或設定這個 Point 的 Y 座標。Gets or sets the y-coordinate of this Point.

方法

Add(Point, Size)

將指定的 Size 加上指定的 PointAdds the specified Size to the specified Point.

Ceiling(PointF)

藉由將 PointF 的值捨入為下一個較大的整數值,來將指定的 Point 轉換成 PointFConverts the specified PointF to a Point by rounding the values of the PointF to the next higher integer values.

Equals(Object)

指定這個 Point 是否包含與指定 Object 相同的座標。Specifies whether this Point contains the same coordinates as the specified Object.

Equals(Point)
GetHashCode()

傳回這個 Point 的雜湊程式碼。Returns a hash code for this Point.

Offset(Int32, Int32)

根據指定的數量來轉換這個 PointTranslates this Point by the specified amount.

Offset(Point)

根據指定的 Point 來轉換這個 PointTranslates this Point by the specified Point.

Round(PointF)

藉由將 PointF 值捨入為最接近的整數值,來將指定的 Point 轉換為 PointF 物件。Converts the specified PointF to a Point object by rounding the PointF values to the nearest integer.

Subtract(Point, Size)

傳回值,該值為從指定的 Size 減去指定的 Point 得到的結果。Returns the result of subtracting specified Size from the specified Point.

ToString()

將這個 Point 轉換為人們可讀取的字串。Converts this Point to a human-readable string.

Truncate(PointF)

藉由截斷 PointF 的值,來將指定的 Point 轉換為 PointFConverts the specified PointF to a Point by truncating the values of the PointF.

運算子

Addition(Point, Size)

根據指定的 Point 來轉換 SizeTranslates a Point by a given Size.

Equality(Point, Point)

比較兩個 Point 物件。Compares two Point objects. 結果會指定兩個 X 物件的 YPoint 屬性值是否相等。The result specifies whether the values of the X and Y properties of the two Point objects are equal.

Explicit(Point to Size)

將指定的 Point 結構轉換成 Size 結構。Converts the specified Point structure to a Size structure.

Implicit(Point to PointF)

將指定的 Point 結構轉換成 PointF 結構。Converts the specified Point structure to a PointF structure.

Inequality(Point, Point)

比較兩個 Point 物件。Compares two Point objects. 結果會指定兩個 X 物件的 YPoint 屬性值是否不相等。The result specifies whether the values of the X or Y properties of the two Point objects are unequal.

Subtraction(Point, Size)

根據指定 Point 的負數來轉換 SizeTranslates a Point by the negative of a given Size.

適用於