Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Rect.Offset Method (Vector)

Translates this rectangle by the specified amount.

Namespace: System.Windows
Assembly: WindowsBase (in windowsbase.dll)

public void Offset (
	Vector offsetVector
)
public void Offset (
	Vector offsetVector
)
public function Offset (
	offsetVector : Vector
)
You cannot use methods in XAML.

Parameters

offsetVector

The horizontal and vertical amounts to move the rectangle.

Exception typeCondition

InvalidOperationException

This method was called on the Empty rectangle.

Calling this method on the empty rectangle (Rect.Empty) is illegal.

The following example shows how to use the Offset method to change the position of a rectangle.

private Point offsetExample1()
{
    // Initialize new rectangle.
    Rect myRectangle = new Rect();

    // The Location property specifies the coordinates of the upper left-hand 
    // corner of the rectangle. 
    myRectangle.Location = new Point(10, 5);

    // Set the Size property of the rectangle with a width of 200
    // and a height of 50.
    myRectangle.Size = new Size(200, 50);

    // Create a vector to use to offset the position of the rectangle.
    Vector vector1 = new Vector(20, 30);

    // The Offset method translates this rectangle by the specified vector.
    // myRectangle location changed from 10,5 to 30,35.
    myRectangle.Offset(vector1);

    // This rectangle's location changed from 10,5 to 30,35.
    return myRectangle.Location;

}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft