Point Point Point Point Struct

定義

表示整數 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 Form。This example is designed to be used with Windows Forms. 建立表單,其中包含Button名為subtractButtonCreate a form that contains a Button named subtractButton. 將程式碼貼到表單,並呼叫CreatePointsAndSizes表單的方法Paint事件處理方法,傳遞e做為PaintEventArgsPaste 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

備註

要轉換PointPointF,使用ImplicitTo convert a Point to a PointF, use Implicit.

建構函式

Point(Size) Point(Size) Point(Size) Point(Size)

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

Point(Int32) Point(Int32) Point(Int32) Point(Int32)

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

Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32) Point(Int32, Int32)

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

欄位

Empty Empty Empty Empty

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

屬性

IsEmpty IsEmpty IsEmpty IsEmpty

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

X X X X

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

Y Y Y Y

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

方法

Add(Point, Size) Add(Point, Size) Add(Point, Size) Add(Point, Size)

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

Ceiling(PointF) Ceiling(PointF) Ceiling(PointF) 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(Point) Equals(Point) Equals(Point) Equals(Point)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

Offset(Int32, Int32) Offset(Int32, Int32) Offset(Int32, Int32) Offset(Int32, Int32)

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

Offset(Point) Offset(Point) Offset(Point) Offset(Point)

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

Round(PointF) Round(PointF) Round(PointF) Round(PointF)

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

Subtract(Point, Size) Subtract(Point, Size) Subtract(Point, Size) Subtract(Point, Size)

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

ToString() ToString() ToString() ToString()

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

Truncate(PointF) Truncate(PointF) Truncate(PointF) Truncate(PointF)

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

運算子

Addition(Point, Size) Addition(Point, Size) Addition(Point, Size) Addition(Point, Size)

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

Equality(Point, Point) Equality(Point, Point) Equality(Point, Point) 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) Explicit(Point to Size) Explicit(Point to Size) Explicit(Point to Size)

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

Implicit(Point to PointF) Implicit(Point to PointF) Implicit(Point to PointF) Implicit(Point to PointF)

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

Inequality(Point, Point) Inequality(Point, Point) Inequality(Point, Point) 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) Subtraction(Point, Size) Subtraction(Point, Size) Subtraction(Point, Size)

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

適用於