Rect.Offset 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將矩形移動指定幅度。
多載
| 名稱 | Description |
|---|---|
| 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 物件,你會得到物件的副本,而不是物件的參考。 如果你嘗試更改XY屬性或索引器引用,編譯器就會出錯。 同樣地,呼叫 Offset 屬性或索引器也不會改變底層物件。 如果你想更改被參考為屬性或索引器的值 Rect ,請建立一個新的 Rect,修改其欄位,然後將 back 指派 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 物件,你會得到物件的副本,而不是物件的參考。 如果你嘗試更改XY屬性或索引器引用,編譯器就會出錯。 同樣地,呼叫 Offset 屬性或索引器也不會改變底層物件。 如果你想更改被參考為屬性或索引器的值 Rect ,請建立一個新的 Rect,修改其欄位,然後將 back 指派 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
一個指定新矩形水平與垂直偏移量的向量。
傳回
結果就是長方形。
例外狀況
rect 是 Empty。
範例
以下範例展示了如何使用此 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
新矩形的垂直偏移量。
傳回
結果就是長方形。
例外狀況
rect 是 Empty。
範例
以下範例展示了如何使用此 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()呼叫此方法。