Rectangle Rectangle Rectangle Rectangle Constructors

定義

オーバーロード

Rectangle(Point, Size) Rectangle(Point, Size) Rectangle(Point, Size)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。Initializes a new instance of the Rectangle class with the specified location and size.

Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。Initializes a new instance of the Rectangle class with the specified location and size.

Rectangle(Point, Size) Rectangle(Point, Size) Rectangle(Point, Size)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。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

パラメーター

location
Point Point Point Point

四角形領域の左上隅を表す PointA Point that represents the upper-left corner of the rectangular region.

size
Size Size Size Size

四角形領域の幅と高さを表す SizeA Size that represents the width and height of the rectangular region.

Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32) Rectangle(Int32, Int32, Int32, Int32)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。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)

パラメーター

x
Int32 Int32 Int32 Int32

四角形の左上隅の x 座標。The x-coordinate of the upper-left corner of the rectangle.

y
Int32 Int32 Int32 Int32

四角形の左上隅の y 座標。The y-coordinate of the upper-left corner of the rectangle.

width
Int32 Int32 Int32 Int32

四角形の幅。The width of the rectangle.

height
Int32 Int32 Int32 Int32

四角形の高さ。The height of the rectangle.

次のコード例は、 RectangleIntersectIsEmpty、およびIntersectsWithの各メンバーを示しています。The following code example demonstrates the Rectangle, Intersect, IsEmpty, and IntersectsWith members. この例は、Windows フォームで使用する必要があります。This example should be used with a Windows Form. このコードをフォームに貼り付け、フォームのPaintイベントを処理するときにこのメソッドを呼び出して、としてPaintEventArgs渡しeます。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

適用対象