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呼び出すと、 プロパティと Y プロパティを直接変更Xできる場合にのみ効果があることに注意してください。 は値型であるため Rect 、プロパティまたはインデクサーを使用してオブジェクトを参照 Rect すると、オブジェクトへの参照ではなく、オブジェクトのコピーが取得されます。 プロパティまたはインデクサー参照で または Y を変更Xしようとすると、コンパイラ エラーが発生します。 同様に、 プロパティまたはインデクサーで を呼び出 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呼び出すと、 プロパティと Y プロパティを直接変更Xできる場合にのみ効果があることに注意してください。 は値型であるため Rect 、プロパティまたはインデクサーを使用してオブジェクトを参照 Rect すると、オブジェクトへの参照ではなく、オブジェクトのコピーが取得されます。 プロパティまたはインデクサー参照で または Y を変更Xしようとすると、コンパイラ エラーが発生します。 同様に、 プロパティまたはインデクサーで を呼び出 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) を使用してこのメソッドを呼び出すことは許可されていません。

適用対象