Rect.Offset メソッド

定義

指定した量だけ四角形を移動します。

オーバーロード

名前 説明
Offset(Vector)

指定したベクトルで四角形を移動します。

Offset(Double, Double)

指定した水平方向と垂直方向の量だけ四角形を移動します。

Offset(Rect, Vector)

指定したベクターを使用して、指定した四角形からオフセットされた四角形を返します。

Offset(Rect, Double, Double)

指定した水平方向および垂直方向の量を使用して、指定した四角形からオフセットされた四角形を返します。

Offset(Vector)

指定したベクトルで四角形を移動します。

public:
 void Offset(System::Windows::Vector offsetVector);
public void Offset(System.Windows.Vector offsetVector);
member this.Offset : System.Windows.Vector -> unit
Public Sub Offset (offsetVector As Vector)

パラメーター

offsetVector
Vector

四角形を移動する水平方向と垂直方向の量を指定するベクター。

例外

このメソッドは、 Empty 四角形で呼び出されます。

次の例は、 Offset(Vector) メソッドを使用して四角形の位置を変更する方法を示しています。

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;
}

注釈

空の四角形 (Rect.Empty) でこのメソッドを呼び出すことは許可されていません。

Offset メソッドの呼び出しは、XプロパティとYプロパティを直接変更できる場合にのみ有効です。 Rectは値型であるため、プロパティまたはインデクサーを使用してRect オブジェクトを参照すると、オブジェクトへの参照ではなく、オブジェクトのコピーが取得されます。 プロパティまたはインデクサー参照の X または Y を変更しようとすると、コンパイラ エラーが発生します。 同様に、プロパティまたはインデクサーで Offset を呼び出すと、基になるオブジェクトは変更されません。 プロパティまたはインデクサーとして参照される Rect の値を変更する場合は、新しい Rectを作成し、そのフィールドを変更してから、 Rect をプロパティまたはインデクサーに割り当てます。

適用対象

Offset(Double, Double)

指定した水平方向と垂直方向の量だけ四角形を移動します。

public:
 void Offset(double offsetX, double offsetY);
public void Offset(double offsetX, double offsetY);
member this.Offset : double * double -> unit
Public Sub Offset (offsetX As Double, offsetY As Double)

パラメーター

offsetX
Double

四角形を水平方向に移動する量。

offsetY
Double

四角形を垂直方向に移動する量。

例外

このメソッドは、 Empty 四角形で呼び出されます。

次の例は、 Offset(Double, Double) メソッドを使用して四角形の位置を変更する方法を示しています。

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;
}

注釈

空の四角形 (Rect.Empty) でこのメソッドを呼び出すことは許可されていません。

Offset メソッドの呼び出しは、XプロパティとYプロパティを直接変更できる場合にのみ有効です。 Rectは値型であるため、プロパティまたはインデクサーを使用してRect オブジェクトを参照すると、オブジェクトへの参照ではなく、オブジェクトのコピーが取得されます。 プロパティまたはインデクサー参照の X または Y を変更しようとすると、コンパイラ エラーが発生します。 同様に、プロパティまたはインデクサーで Offset を呼び出すと、基になるオブジェクトは変更されません。 プロパティまたはインデクサーとして参照される Rect の値を変更する場合は、新しい Rectを作成し、そのフィールドを変更してから、 Rect をプロパティまたはインデクサーに割り当てます。

適用対象

Offset(Rect, Vector)

指定したベクターを使用して、指定した四角形からオフセットされた四角形を返します。

public:
 static System::Windows::Rect Offset(System::Windows::Rect rect, System::Windows::Vector offsetVector);
public static System.Windows.Rect Offset(System.Windows.Rect rect, System.Windows.Vector offsetVector);
static member Offset : System.Windows.Rect * System.Windows.Vector -> System.Windows.Rect
Public Shared Function Offset (rect As Rect, offsetVector As Vector) As Rect

パラメーター

rect
Rect

元の四角形。

offsetVector
Vector

新しい四角形の水平方向と垂直方向のオフセットを指定するベクター。

返品

結果の四角形。

例外

rectEmptyです。

次の例は、 Offset(Rect, Vector) メソッドを使用して四角形の位置を変更する方法を示しています。

private Point offsetExample3()
{
    // 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 the specified rectangle by the specified amount 
    // and returns the resulting Rect. 
    // resultRect location changed from 10,5 to 30,35.
    Rect resultRect = Rect.Offset(myRectangle, vector1);

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

注釈

空の四角形 (Rect.Empty) でこのメソッドを呼び出すことは許可されていません。

適用対象

Offset(Rect, Double, Double)

指定した水平方向および垂直方向の量を使用して、指定した四角形からオフセットされた四角形を返します。

public:
 static System::Windows::Rect Offset(System::Windows::Rect rect, double offsetX, double offsetY);
public static System.Windows.Rect Offset(System.Windows.Rect rect, double offsetX, double offsetY);
static member Offset : System.Windows.Rect * double * double -> System.Windows.Rect
Public Shared Function Offset (rect As Rect, offsetX As Double, offsetY As Double) As Rect

パラメーター

rect
Rect

移動する四角形。

offsetX
Double

新しい四角形の水平方向のオフセット。

offsetY
Double

新しい四角形の垂直方向のオフセット。

返品

結果の四角形。

例外

rectEmptyです。

次の例は、 Offset(Rect, Double, Double) メソッドを使用して四角形の位置を変更する方法を示しています。

private Point offsetExample4()
{
    // 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 the specified rectangle by the specified horizontal 
    // and vertical amounts and returns the resulting Rect. 
    // resultRect location changed from 10,5 to 30,35.
    Rect resultRect = Rect.Offset(myRectangle, 20, 30);

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

注釈

空の四角形 (Rect.Empty) でこのメソッドを呼び出すことは許可されていません。

適用対象