Point.Offset(Double, Double) Method

Definition

Offsets a point's X and Y coordinates by the specified amounts.

C#
public void Offset(double offsetX, double offsetY);

Parameters

offsetX
Double

The amount to offset the point's X coordinate.

offsetY
Double

The amount to offset the point's Y coordinate.

Examples

The following example shows how to offset the X and Y values of a Point structure.

C#
private Point offsetExample()
{
    
    Point pointResult = new Point(10, 5);

    // Offset Point X value by 20 and Y value by 30.
    // pointResult is now equal to (30,35)
    pointResult.Offset(20, 30);

    return pointResult;
}

Remarks

This operation is equivalent to adding a Point to a Vector.

Note that calling the Offset method will only have an effect if you can change the X and Y properties directly. Because Point is a value type, if you reference a Point object by using a property or indexer, you get a copy of the object, not a reference to the object. If you attempt to change X or Y on a property or indexer reference, a compiler error occurs. Similarly, calling Offset on the property or indexer will not change the underlying object. If you want to change the value of a Point that is referenced as a property or indexer, create a new Point, modify its fields, and then assign the Point back to the property or indexer.

Applies to

Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10