Rectangle コンストラクター

定義

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。

オーバーロード

Rectangle(Point, Size)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。

Rectangle(Int32, Int32, Int32, Int32)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。

Rectangle(Point, Size)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。

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)

パラメーター

location
Point

四角形領域の左上隅を表す Point

size
Size

四角形領域の幅と高さを表す Size

適用対象

Rectangle(Int32, Int32, Int32, Int32)

指定した位置とサイズで、Rectangle クラスの新しいインスタンスを初期化します。

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

四角形の左上隅の x 座標。

y
Int32

四角形の左上隅の y 座標。

width
Int32

四角形の幅。

height
Int32

四角形の高さ。

次のコード例は、、IntersectIsEmpty、および の各メンバーをRectangleIntersectsWith示しています。 この例は、Windows フォームで使用する必要があります。 フォームにこのコードを貼り付け、フォームのPaintイベントを処理するときに このメソッドを呼び出し、 を としてPaintEventArgs渡しますe

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

適用対象