System.Drawing.Point Structure

The Point structure represents an ordered pair of x and y coordinates that defines a point in two-dimensional space.

Namespace: System.Drawing

Assembly: System.Drawing (in System.Drawing.dll)

Syntax

public struct Point

Remarks

The Point structure is used to represent a location, typically on a screen or in a graphics coordinate system. It provides fields for the x and y coordinates, as well as methods for manipulating and comparing points.

This structure is a value type. For a list of the members of this object, see the Point members topic.

Constructors

Name Description
Point(int x, int y) Initializes a new instance of the Point structure with the specified coordinates.

Properties

Name Description
IsEmpty Gets a value indicating whether this Point has been initialized to null.
X Gets or sets the x-coordinate of this Point.
Y Gets or sets the y-coordinate of this Point.

Methods

Name Description
Add(Point pt1, Point pt2) Translates a point by the specified dimensions.
Ceiling(PointF value) Converts this PointF structure to a new Point structure by performing a rounding operation on the x and y members.
Contains(int x, int y) Determines whether the specified point is within the bounds of this Rectangle. (Assumes usage within a conceptual bounding box context).
Divide(Point pt1, float divider) Divides the elements of a Point by a specified divisor.
Equals(object obj) Determines whether the specified object is a Point structure and has the same coordinates as the specified structure.
Equals(Point point) Determines whether two Point structures have the same coordinates.
Floor(PointF value) Converts this PointF structure to a new Point structure by performing a ceiling operation on the x and y members.
Offset(int dx, int dy) Translates this Point by the specified amount.
Offset(Point point) Translates this Point by the specified Point.
Subtract(Point pt1, Point pt2) Subtracts the coordinates of one point from the coordinates of another point.
ToString() Returns a string representation of this Point.
Truncate(PointF value) Converts this PointF structure to a new Point structure by truncating the coordinates.

Operators

Operator Description
== Compares two Point structures for equality.
!= Compares two Point structures for inequality.

Example

The following example demonstrates how to create and use the Point structure.

using System;
using System.Drawing;

public class PointExample
{
    public static void Main(string[] args)
    {
        // Create a new Point
        Point myPoint = new Point(10, 20);
        Console.WriteLine($"Created Point: X={myPoint.X}, Y={myPoint.Y}");

        // Create another Point
        Point anotherPoint = new Point(30, 40);
        Console.WriteLine($"Another Point: X={anotherPoint.X}, Y={anotherPoint.Y}");

        // Add two points
        Point sumPoint = Point.Add(myPoint, anotherPoint);
        Console.WriteLine($"Sum of points: X={sumPoint.X}, Y={sumPoint.Y}");

        // Check for equality
        bool isEqual = myPoint.Equals(anotherPoint);
        Console.WriteLine($"Are myPoint and anotherPoint equal? {isEqual}");

        // Offset the point
        myPoint.Offset(5, -5);
        Console.WriteLine($"Offset Point: X={myPoint.X}, Y={myPoint.Y}");

        // Convert to string
        Console.WriteLine($"String representation: {myPoint.ToString()}");
    }
}

See Also