Rectangle.IntersectsWith(Rectangle) Rectangle.IntersectsWith(Rectangle) Rectangle.IntersectsWith(Rectangle) Rectangle.IntersectsWith(Rectangle) Method

Définition

Détermine si ce rectangle croise rect.Determines if this rectangle intersects with rect.

public:
 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

Paramètres

rect
Rectangle Rectangle Rectangle Rectangle

Rectangle à tester.The rectangle to test.

Retours

Si l'intersection existe, cette méthode retourne true ; sinon, false.This method returns true if there is any intersection, otherwise false.

Exemples

L’exemple de code suivant montre le Intersect, IsEmpty et le IntersectsWith membres.The following code example demonstrates the Intersect, IsEmpty and the IntersectsWith members. Cet exemple doit être utilisé avec un Windows Form.This example should be used with a Windows Form. Collez ce code dans un formulaire et appelez cette méthode lors du traitement de Paint l’événement du e formulaire PaintEventArgs, en passant comme.Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.

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

S’applique à