Rectangle.Union(Rectangle, Rectangle) 메서드

정의

두 개의 Rectangle 구조체의 통합 부분을 포함하는 Rectangle 구조체를 가져옵니다.

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

매개 변수

a
Rectangle

통합할 사각형입니다.

b
Rectangle

통합할 사각형입니다.

반환

두 개의 Rectangle 구조체의 통합 부분 경계를 설정하는 Rectangle 구조체를 반환합니다.

예제

다음 코드 예제에서는 Union 메서드를 사용하는 방법을 보여 줍니다. 이 예제는 Windows Form에서 사용하도록 설계되었습니다. 양식에 이 코드를 붙여넣고 양식의 Paint 이벤트를 처리할 때 메서드를 호출 ShowRectangleUnion 하여 으로 PaintEventArgs전달 e 합니다.

private:
   void ShowRectangleUnion( PaintEventArgs^ e )
   {
      // Declare two rectangles and draw them.
      Rectangle rectangle1 = Rectangle(30,40,50,100);
      Rectangle rectangle2 = Rectangle(50,60,100,60);
      e->Graphics->DrawRectangle( Pens::Sienna, rectangle1 );
      e->Graphics->DrawRectangle( Pens::BlueViolet, rectangle2 );

      // Declare a third rectangle as a union of the first two.
      Rectangle rectangle3 = Rectangle::Union( rectangle1, rectangle2 );

      // Fill in the third rectangle in a semi-transparent color.
      Color transparentColor = Color::FromArgb( 40, 135, 135, 255 );
      e->Graphics->FillRectangle( gcnew SolidBrush( transparentColor ), rectangle3 );
   }
private void ShowRectangleUnion(PaintEventArgs e)
{

    // Declare two rectangles and draw them.
    Rectangle rectangle1 = new Rectangle(30, 40, 50, 100);
    Rectangle rectangle2 = new Rectangle(50, 60, 100, 60);
    e.Graphics.DrawRectangle(Pens.Sienna, rectangle1);
    e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2);

    // Declare a third rectangle as a union of the first two.
    Rectangle rectangle3 = Rectangle.Union(rectangle1, rectangle2);

    // Fill in the third rectangle in a semi-transparent color.
    Color transparentColor = Color.FromArgb(40, 135, 135, 255);
    e.Graphics.FillRectangle(new SolidBrush(transparentColor), rectangle3);
}
Private Sub ShowRectangleUnion(ByVal e As PaintEventArgs)

    ' Declare two rectangles and draw them.
    Dim rectangle1 As New Rectangle(30, 40, 50, 100)
    Dim rectangle2 As New Rectangle(50, 60, 100, 60)
    e.Graphics.DrawRectangle(Pens.Sienna, rectangle1)
    e.Graphics.DrawRectangle(Pens.BlueViolet, rectangle2)

    ' Declare a third rectangle as a union of the first two.
    Dim rectangle3 As Rectangle = Rectangle.Union(rectangle1, _
        rectangle2)

    ' Fill in the third rectangle in a semi-transparent color.
    Dim transparentColor As Color = Color.FromArgb(40, 135, 135, 255)
    e.Graphics.FillRectangle(New SolidBrush(transparentColor), _
        rectangle3)
End Sub

설명

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

적용 대상