RectangleF.Union(RectangleF, RectangleF) 메서드

정의

통합 부분을 구성하는 두 사각형에 모두 포함되는 세째 사각형을 가능한 한 작게 만듭니다.

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

통합할 사각형입니다.

b
RectangleF

통합할 사각형입니다.

반환

통합 부분을 구성하는 두 사각형에 모두 포함된 세째 RectangleF 구조체를 반환합니다.

예제

이 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 개체인 e가 OnPaint 필요합니다PaintEventArgs. 이 코드는 두 개의 RectangleF s를 만들고 검은색과 빨간색으로 화면에 그립니다. 그리기 목적으로 를 로 Rectangle 변환해야 합니다. 그런 다음, 코드는 메서드를 사용하여 Union 세 번째 RectangleF 를 만들고, 로 Rectangle변환하고, 파란색으로 화면에 그립니다. 세 번째(파란색) 사각형은 다른 두 사각형을 모두 포함할 수 있는 가장 작은 사각형입니다.

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

설명

두 사각형 중 하나가 비어 있으면 모든 값이 0이면 메서드는 시작점(0, Union 0)과 비어 있지 않은 사각형의 높이 및 너비가 있는 사각형을 반환합니다. 예를 들어 두 개의 사각형 A = (0, 0, 0, 0) 및 B = (1, 1, 2, 2)가 있는 경우 A와 B의 합합은 (0, 0, 2, 2)입니다.

적용 대상