PointF Structure
System.Drawing
Represents an ordered pair of floating-point X and Y coordinates that defines a point in two-dimensional space.
Syntax
public struct PointF : System.IEquatable<System.Drawing.PointF>
Fields
Field | Description |
---|---|
X |
The X coordinate of this PointF . |
Y |
The Y coordinate of this PointF . |
Constructors
Constructor | Description |
---|---|
PointF(float x, float y) |
Initializes a new instance of the PointF structure using the specified coordinates. |
Methods
Method | Description |
---|---|
Equals(object obj) |
Determines whether the specified object is a PointF structure with the same location as the specified object. |
Equals(PointF point) |
Determines whether the specified PointF structure has the same location as this PointF structure. |
GetHashCode() |
Returns the hash code for this PointF structure for use in hashing algorithms and data structures such as a hash table. |
ToString() |
Converts this PointF structure to a human-readable string. |
Operators
Operator | Description |
---|---|
== (PointF left, PointF right) |
Compares two PointF structures for equality. |
!= (PointF left, PointF right) |
Compares two PointF structures for inequality. |
Remarks
The PointF structure is a value type that is used to represent points with floating-point precision. It is useful for graphics operations where precise positioning is required. Use this structure when you need to store coordinates that are not necessarily integers, such as those obtained from calculations or user input that might involve fractional values.
The X and Y members represent the horizontal and vertical positions, respectively. Together, they define a location on a two-dimensional plane.
Example
using System.Drawing;
public class Example
{
public static void Main()
{
PointF p1 = new PointF(10.5f, 20.2f);
PointF p2 = new PointF(10.5f, 20.2f);
PointF p3 = new PointF(5.0f, 7.5f);
// Check for equality
// Console.WriteLine(p1 == p2); // Output: True
// Console.WriteLine(p1 == p3); // Output: False
// Accessing coordinates
// Console.WriteLine($"X: {p1.X}, Y: {p1.Y}"); // Output: X: 10.5, Y: 20.2
// Convert to string
// Console.WriteLine(p1.ToString()); // Output: {X=10.5, Y=20.2}
}
}