Rect.Offset Método

Definição

Move um retângulo pela quantidade especificada.

Sobrecargas

Offset(Vector)

Move o retângulo pelo vetor especificado.

Offset(Double, Double)

Move o retângulo pelas quantidades horizontal e vertical especificadas.

Offset(Rect, Vector)

Retorna um retângulo que é deslocado do retângulo especificado usando o vetor especificado.

Offset(Rect, Double, Double)

Retorna um retângulo que é deslocado do retângulo especificado usando os valores horizontais e verticais especificados.

Offset(Vector)

Move o retângulo pelo vetor especificado.

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)

Parâmetros

offsetVector
Vector

Um vetor que especifica as quantidades horizontais e verticais para mover o retângulo.

Exceções

Esse método é chamado no retângulo Empty.

Exemplos

O exemplo a seguir mostra como usar o Offset(Vector) método para alterar a posição de um retângulo.

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

Comentários

Chamar esse método em um retângulo vazio (Rect.Empty) não é permitido.

Observe que chamar o Offset método só terá um efeito se você puder alterar as propriedades e Y as X propriedades diretamente. Como Rect é um tipo de valor, se você referenciar um Rect objeto usando uma propriedade ou indexador, receberá uma cópia do objeto, não uma referência ao objeto. Se você tentar alterar X ou Y em uma referência de propriedade ou indexador, ocorrerá um erro do compilador. Da mesma forma, chamar Offset a propriedade ou o indexador não alterará o objeto subjacente. Se você quiser alterar o valor de um Rect que é referenciado como uma propriedade ou indexador, crie um novo Rect, modifique seus campos e, em seguida, atribua o Rect back à propriedade ou indexador.

Aplica-se a

Offset(Double, Double)

Move o retângulo pelas quantidades horizontal e vertical especificadas.

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)

Parâmetros

offsetX
Double

O valor para mover o retângulo horizontalmente.

offsetY
Double

O valor para mover o retângulo verticalmente.

Exceções

Esse método é chamado no retângulo Empty.

Exemplos

O exemplo a seguir mostra como usar o Offset(Double, Double) método para alterar a posição de um retângulo.

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

Comentários

Chamar esse método em um retângulo vazio (Rect.Empty) não é permitido.

Observe que chamar o Offset método só terá um efeito se você puder alterar as propriedades e Y as X propriedades diretamente. Como Rect é um tipo de valor, se você referenciar um Rect objeto usando uma propriedade ou indexador, receberá uma cópia do objeto, não uma referência ao objeto. Se você tentar alterar X ou Y em uma referência de propriedade ou indexador, ocorrerá um erro do compilador. Da mesma forma, chamar Offset a propriedade ou o indexador não alterará o objeto subjacente. Se você quiser alterar o valor de um Rect referenciado como uma propriedade ou indexador, crie um novo Rect, modifique seus campos e atribua o Rect back à propriedade ou indexador.

Aplica-se a

Offset(Rect, Vector)

Retorna um retângulo que é deslocado do retângulo especificado usando o vetor especificado.

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

Parâmetros

rect
Rect

O retângulo original.

offsetVector
Vector

Um vetor que especifica os deslocamentos horizontais e verticais para o novo retângulo.

Retornos

Rect

O retângulo resultante.

Exceções

Exemplos

O exemplo a seguir mostra como usar o Offset(Rect, Vector) método para alterar a posição de um retângulo.

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

Comentários

Chamar esse método com um retângulo vazio (Rect.Empty) não é permitido.

Aplica-se a

Offset(Rect, Double, Double)

Retorna um retângulo que é deslocado do retângulo especificado usando os valores horizontais e verticais especificados.

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

Parâmetros

rect
Rect

O retângulo a ser movido.

offsetX
Double

O deslocamento horizontal para o novo retângulo.

offsetY
Double

O deslocamento vertical para o novo retângulo.

Retornos

Rect

O retângulo resultante.

Exceções

Exemplos

O exemplo a seguir mostra como usar o Offset(Rect, Double, Double) método para alterar a posição de um retângulo.

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

Comentários

Chamar esse método com um retângulo vazio (Rect.Empty) não é permitido.

Aplica-se a