Rectangle.Offset 方法

定義

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

多載

Offset(Point)

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

Offset(Int32, Int32)

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

Offset(Point)

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

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

public:
 void Offset(System::Drawing::Point pos);
public void Offset (System.Drawing.Point pos);
member this.Offset : System.Drawing.Point -> unit
Public Sub Offset (pos As Point)

參數

pos
Point

要位移位置的數量。

範例

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

private:
   [UIPermission(SecurityAction::Demand, Window=UIPermissionWindow::AllWindows)]
   void DrawFirstRectangle()
   {
      Rectangle rectangle1 = Rectangle(70,70,100,150);
      ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
   }

   void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      Rectangle rectangle1 = Rectangle(70,70,100,150);

      // 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 ) )
      {
         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 );
      }
   }
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);
    }
}
Dim rectangle1 As New Rectangle(70, 70, 100, 150)

Private Sub DrawFirstRectangle()
    ControlPaint.DrawReversibleFrame(rectangle1, _
        SystemColors.Highlight, FrameStyle.Thick)
End Sub

Private Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles Button1.Click

    ' Get the bounds of the screen.
    Dim screenRectangle As Rectangle = Screen.PrimaryScreen.Bounds

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

        ' 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)
    End If
End Sub

備註

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

適用於

Offset(Int32, Int32)

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

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

public:
 void Offset(int x, int y);
public void Offset (int x, int y);
member this.Offset : int * int -> unit
Public Sub Offset (x As Integer, y As Integer)

參數

x
Int32

水平位移。

y
Int32

垂直位移。

適用於