Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System.Windows
Point Structure
Point Methods
 Offset Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
Point..::.Offset Method

Updated: April 2011

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

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
Visual Basic
Public Sub Offset ( _
    offsetX As Double, _
    offsetY As Double _
)
C#
public void Offset(
    double offsetX,
    double offsetY
)
Visual C++
public:
void Offset(
    double offsetX, 
    double offsetY
)
F#
member Offset : 
        offsetX:float * 
        offsetY:float -> unit 

Parameters

offsetX
Type: System..::.Double
The amount to offset the point's
X coordinate.
offsetY
Type: System..::.Double
The amount to offset the
point's Y coordinate.

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

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. 

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.
    // point1 is now equal to (30,35)
    pointResult.Offset(20, 30);

    return pointResult;

}

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, 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.

Date

History

Reason

April 2011

Added remark about using Offset with properties and indexers.

Information enhancement.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
I have the same issue      Brian Mullins   |   Edit   |   Show History
Same issue here. Using offset does not move my picturebox. Is there a 'refresh' that needs to be done after using it?
Tags What's this?: Add a tag
Flag as ContentBug
Offset method does not work with Property declaration      Verma.Manish   |   Edit   |   Show History

I am not sure why this is happening but, for me, the Offset method does not work with the Property declaration.
For example, there is a property declared like this;

private System.Windows.Point mNewOffset;
public System.Windows.Point NewOffset
{
get
{
return mNewOffset;
}
private set
{
mNewOffset = value;
}
}

and then when I call the Offset method on 'NewOffset' like this;

NewOffset.Offset(5, 5);

..nothing happens, and the value remains same as before.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker