Rectangle.Offset Metodo

Definizione

Regola la posizione di questo rettangolo in base al valore specificato.

Overload

Offset(Point)

Regola la posizione di questo rettangolo in base al valore specificato.

Offset(Int32, Int32)

Regola la posizione di questo rettangolo in base al valore specificato.

Offset(Point)

Origine:
Rectangle.cs
Origine:
Rectangle.cs
Origine:
Rectangle.cs

Regola la posizione di questo rettangolo in base al valore specificato.

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

Parametri

pos
Point

Valore di offset della posizione.

Esempio

Nell'esempio di codice seguente vengono illustrati i Containsmetodi , e Offset e la SystemPens classe . Questo esempio è progettato per l'uso con un Windows Form. Incollare questo codice in un modulo contenente un pulsante denominato Button1, chiamare DrawFirstRectangle dal costruttore o Load dal metodo del modulo e associare il Button1_Click metodo all'evento del Click pulsante.

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);
    }
}

Commenti

Questo metodo regola la posizione dell'angolo superiore sinistro orizzontalmente in base alla coordinata x del punto specificato e verticalmente in base alla coordinata y del punto specificato.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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)

Origine:
Rectangle.cs
Origine:
Rectangle.cs
Origine:
Rectangle.cs

Regola la posizione di questo rettangolo in base al valore specificato.

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

Parametri

x
Int32

Offset orizzontale.

y
Int32

Offset verticale.

Si applica a

.NET 9 e altre versioni
Prodotto Versioni
.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