RectangleF.Union(RectangleF, RectangleF) メソッド

定義

和集合を形成する 2 つの四角形の両方を含めることができる最小の 3 番目の四角形を作成します。Creates the smallest possible third rectangle that can contain both of two rectangles that form a union.

public:
 static System::Drawing::RectangleF Union(System::Drawing::RectangleF a, System::Drawing::RectangleF b);
public static System.Drawing.RectangleF Union (System.Drawing.RectangleF a, System.Drawing.RectangleF b);
static member Union : System.Drawing.RectangleF * System.Drawing.RectangleF -> System.Drawing.RectangleF
Public Shared Function Union (a As RectangleF, b As RectangleF) As RectangleF

パラメーター

a
RectangleF

結合する四角形。A rectangle to union.

b
RectangleF

結合する四角形。A rectangle to union.

戻り値

和集合を形成する 2 つの四角形の両方が含まれる 3 番目の RectangleF 構造体。A third RectangleF structure that contains both of the two rectangles that form the union.

この例は、Windows フォームで使用するように設計さPaintEventArgsれておりOnPaint 、イベントオブジェクトである e を必要とします。This example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. このコードではRectangleF 、2つのを作成し、黒と赤で画面に描画します。The code creates two RectangleF s and draws them to the screen in black and red. 描画を目的として、をRectangleに変換する必要があることに注意してください。Notice that they have to be converted to Rectangle s for drawing purposes. 次に、 Unionメソッドを使用RectangleFして3番目のを作成Rectangleし、それをに変換して、青で画面に描画します。Then the code creates a third RectangleF using the Union method, converts it to a Rectangle, and draws it to the screen in blue. 3番目の (青の) 四角形は、他の2つの四角形の両方を含めることができる最小の四角形です。Notice the third (blue) rectangle is the smallest possible rectangle that can contain both of the other two rectangles:

public:
   void RectangleFUnionExample( PaintEventArgs^ e )
   {
      // Create two rectangles and draw them to the screen.
      RectangleF firstRectangleF = RectangleF(0,0,75,50);
      RectangleF secondRectangleF = RectangleF(100,100,20,20);

      // Convert the RectangleF structures to Rectangle structures and draw them to the
      // screen.
      Rectangle firstRect = Rectangle::Truncate( firstRectangleF );
      Rectangle secondRect = Rectangle::Truncate( secondRectangleF );
      e->Graphics->DrawRectangle( Pens::Black, firstRect );
      e->Graphics->DrawRectangle( Pens::Red, secondRect );

      // Get the union rectangle.
      RectangleF unionRectangleF = RectangleF::Union( firstRectangleF, secondRectangleF );

      // Draw the unionRectangleF to the screen.
      Rectangle unionRect = Rectangle::Truncate( unionRectangleF );
      e->Graphics->DrawRectangle( Pens::Blue, unionRect );
   }
public void RectangleFUnionExample(PaintEventArgs e)
{
             
    // Create two rectangles and draw them to the screen.
    RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50);
    RectangleF secondRectangleF = new RectangleF(100, 100, 20, 20);
             
    // Convert the RectangleF structures to Rectangle structures and draw them to the
             
    // screen.
    Rectangle firstRect = Rectangle.Truncate(firstRectangleF);
    Rectangle secondRect = Rectangle.Truncate(secondRectangleF);
    e.Graphics.DrawRectangle(Pens.Black, firstRect);
    e.Graphics.DrawRectangle(Pens.Red, secondRect);
             
    // Get the union rectangle.
    RectangleF unionRectangleF = RectangleF.Union(firstRectangleF,
        secondRectangleF);
             
    // Draw the unionRectangleF to the screen.
    Rectangle unionRect = Rectangle.Truncate(unionRectangleF);
    e.Graphics.DrawRectangle(Pens.Blue, unionRect);
}
Public Sub RectangleFUnionExample(ByVal e As PaintEventArgs)

    ' Create two rectangles and draw them to the screen.
    Dim firstRectangleF As New RectangleF(0, 0, 75, 50)
    Dim secondRectangleF As New RectangleF(100, 100, 20, 20)

    ' Convert the RectangleF structures to Rectangle structures and

    ' draw them to the screen.
    Dim firstRect As Rectangle = Rectangle.Truncate(firstRectangleF)
    Dim secondRect As Rectangle = Rectangle.Truncate(secondRectangleF)
    e.Graphics.DrawRectangle(Pens.Black, firstRect)
    e.Graphics.DrawRectangle(Pens.Red, secondRect)

    ' Get the union rectangle.
    Dim unionRectangleF As RectangleF = _
    RectangleF.Union(firstRectangleF, secondRectangleF)

    ' Draw the unionRectangleF to the screen.
    Dim unionRect As Rectangle = Rectangle.Truncate(unionRectangleF)
    e.Graphics.DrawRectangle(Pens.Blue, unionRect)
End Sub

注釈

2つの四角形のいずれかが空の場合は、すべての値がゼロUnionであることを意味します。このメソッドは、開始点が (0, 0) で、空でない四角形の高さと幅を持つ四角形を返します。When one of the two rectangles is empty, meaning all of its values are zero, the Union method returns a rectangle with a starting point of (0, 0), and the height and width of the non-empty rectangle. たとえば、A = (0, 0, 0, 0) と B = (1, 1; 2, 2) の2つの四角形がある場合、A と B の和集合は (0, 0; 2, 2) になります。For example, if you have two rectangles A = (0, 0; 0, 0) and B = (1, 1; 2, 2), then the union of A and B is (0, 0; 2, 2).

適用対象