This documentation is archived and is not being maintained.

Rect.Offset Method (Double, Double)

Translates this rectangle by the specified horizontal and vertical amounts.

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

public void Offset (
	double offsetX,
	double offsetY
)
public void Offset (
	double offsetX, 
	double offsetY
)
public function Offset (
	offsetX : double, 
	offsetY : double
)
You cannot use methods in XAML.

Parameters

offsetX

The amount to move the rectangle horizontally.

offsetY

The amount to move the rectangle vertically.

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 offsetExample2()
{
    // 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);

    // The Offset method translates this rectangle by the specified horizontal and 
    // vertical amounts. 
    // myRectangle location changed from 10,5 to 30,35.
    myRectangle.Offset(20,30);

    // 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
Show: