Rectangle Konstruktory

Definicja

Inicjuje Rectangle nowe wystąpienie klasy o określonej lokalizacji i rozmiarze.

Przeciążenia

Rectangle(Point, Size)

Inicjuje Rectangle nowe wystąpienie klasy o określonej lokalizacji i rozmiarze.

Rectangle(Int32, Int32, Int32, Int32)

Inicjuje Rectangle nowe wystąpienie klasy o określonej lokalizacji i rozmiarze.

Rectangle(Point, Size)

Źródło:
Rectangle.cs
Źródło:
Rectangle.cs
Źródło:
Rectangle.cs

Inicjuje Rectangle nowe wystąpienie klasy o określonej lokalizacji i rozmiarze.

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
Public Sub New (location As Point, size As Size)

Parametry

location
Point

Obiekt Point reprezentujący lewy górny róg prostokątnego regionu.

size
Size

Obiekt Size reprezentujący szerokość i wysokość prostokątnego regionu.

Dotyczy

Rectangle(Int32, Int32, Int32, Int32)

Źródło:
Rectangle.cs
Źródło:
Rectangle.cs
Źródło:
Rectangle.cs

Inicjuje Rectangle nowe wystąpienie klasy o określonej lokalizacji i rozmiarze.

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)

Parametry

x
Int32

Współrzędna x lewego górnego rogu prostokąta.

y
Int32

Współrzędna y lewego górnego rogu prostokąta.

width
Int32

Szerokość prostokąta.

height
Int32

Wysokość prostokąta.

Przykłady

Poniższy przykład kodu przedstawia Rectangleelementy członkowskie , Intersect, IsEmptyi IntersectsWith . Ten przykład powinien być używany z formularzem systemu Windows. Wklej ten kod w formularzu i wywołaj tę metodę podczas obsługi zdarzenia formularza Paint , przekazując e jako 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

Dotyczy