Rectangle.Offset 方法

定義

以指定的數量調整這個矩形的位置。

多載

Offset(Point)

以指定的數量調整這個矩形的位置。

Offset(Int32, Int32)

以指定的數量調整這個矩形的位置。

Offset(Point)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
Rectangle.cs

以指定的數量調整這個矩形的位置。

C#
public void Offset (System.Drawing.Point pos);

參數

pos
Point

要位移位置的數量。

範例

下列程式代碼範例示範 Contains、 和 Offset 方法和 SystemPens 類別。 此範例是設計來搭配 Windows Form 使用。 將此程式代碼貼到包含名為 Button1的按鈕的表單中,從表單的建構函式或Load方法呼叫DrawFirstRectangle,並將方法與按鈕的 Click 事件產生關聯Button1_Click

C#
Rectangle rectangle1 = new Rectangle(70, 70, 100, 150);

private void DrawFirstRectangle()
{
    ControlPaint.DrawReversibleFrame(rectangle1, 
        SystemColors.Highlight, FrameStyle.Thick);
}

private void Button1_Click(object sender, EventArgs e)
{

    // Get the bounds of the screen.
    Rectangle screenRectangle = Screen.PrimaryScreen.Bounds;

    // Check to see if the rectangle is within the bounds of the screen.
    if (screenRectangle.Contains(rectangle1))

        // If so, erase the previous rectangle.
    {
        ControlPaint.DrawReversibleFrame(rectangle1, 
            SystemColors.Highlight, FrameStyle.Thick);

        // Call the Offset method to move the rectangle.
        rectangle1.Offset(20, 20);

        // Draw the new, offset rectangle.
        ControlPaint.DrawReversibleFrame(rectangle1, 
            SystemColors.Highlight, FrameStyle.Thick);
    }
}

備註

這個方法會依指定點的 x 座標水平調整左上角的位置,並以指定點的 Y 座標垂直調整。

適用於

.NET 9 及其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Offset(Int32, Int32)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
Rectangle.cs

以指定的數量調整這個矩形的位置。

C#
public void Offset (int x, int y);

參數

x
Int32

水平位移。

y
Int32

垂直位移。

適用於

.NET 9 及其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1