Skip to main content
.NET Framework Class Library
Point Structure

Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Syntax
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<TypeConverterAttribute(GetType(PointConverter))> _
Public Structure Point
[SerializableAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(PointConverter))]
public struct Point
[SerializableAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(PointConverter))]
public value class Point
[<Sealed>]
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
[<TypeConverterAttribute(typeof(PointConverter))>]
type Point =  struct end

The Point type exposes the following members.

Constructors
 NameDescription
Public methodPoint(Int32)Initializes a new instance of the Point class using coordinates specified by an integer value.
Public methodPoint(Size)Initializes a new instance of the Point class from a Size.
Public methodPoint(Int32, Int32)Initializes a new instance of the Point class with the specified coordinates.
Top
Properties
 NameDescription
Public propertyIsEmptyGets a value indicating whether this Point is empty.
Public propertyXGets or sets the x-coordinate of this Point.
Public propertyYGets or sets the y-coordinate of this Point.
Top
Methods
 NameDescription
Public methodStatic memberAddAdds the specified Size to the specified Point.
Public methodStatic memberCeilingConverts the specified PointF to a Point by rounding the values of the PointF to the next higher integer values.
Public methodEqualsSpecifies whether this Point contains the same coordinates as the specified Object. (Overrides ValueType..::.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns a hash code for this Point. (Overrides ValueType..::.GetHashCode()()().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOffset(Point)Translates this Point by the specified Point.
Public methodOffset(Int32, Int32)Translates this Point by the specified amount.
Public methodStatic memberRoundConverts the specified PointF to a Point object by rounding the Point values to the nearest integer.
Public methodStatic memberSubtractReturns the result of subtracting specified Size from the specified Point.
Public methodToStringConverts this Point to a human-readable string. (Overrides ValueType..::.ToString()()().)
Public methodStatic memberTruncateConverts the specified PointF to a Point by truncating the values of the Point.
Top
Operators
 NameDescription
Public operatorStatic memberAdditionTranslates a Point by a given Size.
Public operatorStatic memberEqualityCompares two Point objects. The result specifies whether the values of the X and Y properties of the two Point objects are equal.
Public operatorStatic memberExplicitNarrowingExplicitExplicit(Point to Size)Converts the specified Point structure to a Size structure.
Public operatorStatic memberImplicitWideningImplicitImplicit(Point to PointF)Converts the specified Point structure to a PointF structure.
Public operatorStatic memberInequalityCompares two Point objects. The result specifies whether the values of the X or Y properties of the two Point objects are unequal.
Public operatorStatic memberSubtractionTranslates a Point by the negative of a given Size.
Top
Fields
 NameDescription
Public fieldStatic memberEmptyRepresents a Point that has X and Y values set to zero.
Top
Remarks

To convert a Point to a PointF, use ImplicitWideningImplicitImplicit.

Examples

The following code example creates points and sizes using several of the overloaded operators defined for these types. It also demonstrates how to use the SystemPens class.

This example is designed to be used with Windows Forms. Create a form that contains a Button named subtractButton. Paste the code into the form and call the CreatePointsAndSizes method from the form's Paint event-handling method, passing e as PaintEventArgs.


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


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);
    }

}


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 );
   }
}

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?