Rectangle Construtores

Definição

Inicializa uma nova instância da classe Rectangle com o local e o tamanho especificados.Initializes a new instance of the Rectangle class with the specified location and size.

Sobrecargas

Rectangle(Point, Size)

Inicializa uma nova instância da classe Rectangle com o local e o tamanho especificados.Initializes a new instance of the Rectangle class with the specified location and size.

Rectangle(Int32, Int32, Int32, Int32)

Inicializa uma nova instância da classe Rectangle com o local e o tamanho especificados.Initializes a new instance of the Rectangle class with the specified location and size.

Rectangle(Point, Size)

Inicializa uma nova instância da classe Rectangle com o local e o tamanho especificados.Initializes a new instance of the Rectangle class with the specified location and size.

public:
 Rectangle(System::Drawing::Point location, System::Drawing::Size size);
public Rectangle (System.Drawing.Point location, System.Drawing.Size size);
new System.Drawing.Rectangle : System.Drawing.Point * System.Drawing.Size -> System.Drawing.Rectangle

Parâmetros

location
Point

Um Point que representa o canto superior esquerdo da região retangular.A Point that represents the upper-left corner of the rectangular region.

size
Size

Um Size que representa a largura e a altura da região retangular.A Size that represents the width and height of the rectangular region.

Rectangle(Int32, Int32, Int32, Int32)

Inicializa uma nova instância da classe Rectangle com o local e o tamanho especificados.Initializes a new instance of the Rectangle class with the specified location and size.

public:
 Rectangle(int x, int y, int width, int height);
public Rectangle (int x, int y, int width, int height);
new System.Drawing.Rectangle : int * int * int * int -> System.Drawing.Rectangle
Public Sub New (x As Integer, y As Integer, width As Integer, height As Integer)

Parâmetros

x
Int32

A coordenada X do canto superior esquerdo do retângulo.The x-coordinate of the upper-left corner of the rectangle.

y
Int32

A coordenada y do canto superior esquerdo do retângulo.The y-coordinate of the upper-left corner of the rectangle.

width
Int32

A largura do retângulo.The width of the rectangle.

height
Int32

A altura do retângulo.The height of the rectangle.

Exemplos

O exemplo de código a seguir demonstra os membros Rectangle, Intersect, IsEmpty e IntersectsWith.The following code example demonstrates the Rectangle, Intersect, IsEmpty, and IntersectsWith members. Este exemplo deve ser usado com um Windows Form.This example should be used with a Windows Form. Cole esse código em um formulário e chame esse método ao manipular o evento Paint do formulário, passando e como PaintEventArgs.Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.

private:
   void InstanceRectangleIntersection( PaintEventArgs^ e )
   {
      Rectangle rectangle1 = Rectangle(50,50,200,100);
      Rectangle rectangle2 = Rectangle(70,20,100,200);
      e->Graphics->DrawRectangle( Pens::Black, rectangle1 );
      e->Graphics->DrawRectangle( Pens::Red, rectangle2 );
      if ( rectangle1.IntersectsWith( rectangle2 ) )
      {
         rectangle1.Intersect( rectangle2 );
         if (  !rectangle1.IsEmpty )
         {
            e->Graphics->FillRectangle( Brushes::Green, rectangle1 );
         }
      }
   }
private void InstanceRectangleIntersection(PaintEventArgs e)
{

    Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);
    Rectangle rectangle2 = new Rectangle(70, 20, 100, 200);

    e.Graphics.DrawRectangle(Pens.Black, rectangle1);
    e.Graphics.DrawRectangle(Pens.Red, rectangle2);

    if (rectangle1.IntersectsWith(rectangle2))
    {
        rectangle1.Intersect(rectangle2);
        if (!rectangle1.IsEmpty)
        {
            e.Graphics.FillRectangle(Brushes.Green, rectangle1);
        }
    }
}
  Private Sub InstanceRectangleIntersection( _
      ByVal e As PaintEventArgs)

      Dim rectangle1 As New Rectangle(50, 50, 200, 100)
      Dim rectangle2 As New Rectangle(70, 20, 100, 200)

      e.Graphics.DrawRectangle(Pens.Black, rectangle1)
      e.Graphics.DrawRectangle(Pens.Red, rectangle2)

      If (rectangle1.IntersectsWith(rectangle2)) Then
          rectangle1.Intersect(rectangle2)
          If Not (rectangle1.IsEmpty) Then
              e.Graphics.FillRectangle(Brushes.Green, rectangle1)
          End If
      End If
  End Sub

Aplica-se a