Rectangle.IntersectsWith(Rectangle) 메서드


이 사각형이 rect와 교차되는지 여부를 확인합니다.Determines if this rectangle intersects with rect.

 bool IntersectsWith(System::Drawing::Rectangle rect);
public bool IntersectsWith (System.Drawing.Rectangle rect);
member this.IntersectsWith : System.Drawing.Rectangle -> bool
Public Function IntersectsWith (rect As Rectangle) As Boolean

매개 변수


테스트할 사각형입니다.The rectangle to test.


교차 부분이 있으면 이 메서드는 true를 반환하고, 그렇지 않으면 false를 반환합니다.This method returns true if there is any intersection, otherwise false.


다음 코드 예제에서는 Intersect, IsEmptyIntersectsWith 멤버를 보여 줍니다.The following code example demonstrates the Intersect, IsEmpty and the IntersectsWith members. 이 예제에서는 Windows Form을 사용 하 여 사용 해야 합니다.This example should be used with a Windows Form. 폼에이 코드를 붙여넣고 폼의 Paint 이벤트를 처리할 때이 메서드를 호출 하 여 e PaintEventArgs으로 전달 합니다.Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.

   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))
        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
          If Not (rectangle1.IsEmpty) Then
              e.Graphics.FillRectangle(Brushes.Green, rectangle1)
          End If
      End If
  End Sub

적용 대상