Rectangle.Offset Metod

Definition

Justerar platsen för den här rektangeln med den angivna mängden.

Överlagringar

Name Description
Offset(Point)

Justerar platsen för den här rektangeln med den angivna mängden.

Offset(Int32, Int32)

Justerar platsen för den här rektangeln med den angivna mängden.

Offset(Point)

Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs

Justerar platsen för den här rektangeln med den angivna mängden.

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)

Parametrar

pos
Point

Belopp för att förskjuta platsen.

Exempel

I följande kodexempel visas Containsmetoderna , och Offset och SystemPens klassen. Det här exemplet är utformat för användning med ett Windows formulär. Klistra in den här koden i ett formulär som innehåller en knapp med namnet Button1, anropa DrawFirstRectangle från formulärets konstruktor eller Load metod och associera Button1_Click metoden med knappens Click händelse.

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

Kommentarer

Den här metoden justerar platsen för det övre vänstra hörnet vågrätt med x-koordinaten för den angivna punkten och lodrätt efter y-koordinaten för den angivna punkten.

Gäller för

Offset(Int32, Int32)

Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs
Källa:
Rectangle.cs

Justerar platsen för den här rektangeln med den angivna mängden.

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)

Parametrar

x
Int32

Den vågräta förskjutningen.

y
Int32

Den lodräta förskjutningen.

Gäller för