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 窗体一起使用。This example is designed to be used with Windows Forms. 创建一个包含Button名为subtractButton的窗体。Create a form that contains a Button named subtractButton. 将代码粘贴到窗体中, 并CreatePointsAndSizes从窗体的Paint事件处理方法中调用方法, ePaintEventArgs将作为传递。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(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,其 XY 值设为零。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)

将此 Point 平移指定的量。Translates 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 转换为 PointF 对象。Converts the specified PointF to a Point object by rounding the PointF 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 转换为 PointFConverts the specified PointF to a Point by truncating the values of the PointF.

操作员

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 平移给定 Size 的负数。Translates a Point by the negative of a given Size.

适用于