Rectangle.Intersect Metodo

Definizione

Determina la struttura Rectangle che rappresenta l'intersezione di due rettangoli.

Overload

Intersect(Rectangle, Rectangle)

Restituisce una terza struttura Rectangle che rappresenta l'intersezione di altre due strutture Rectangle. Se non è presente alcuna intersezione, verrà restituita una struttura Rectangle vuota.

Intersect(Rectangle)

Sostituisce l'oggetto Rectangle con la sua intersezione con l'oggetto Rectangle specificato.

Intersect(Rectangle, Rectangle)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Restituisce una terza struttura Rectangle che rappresenta l'intersezione di altre due strutture Rectangle. Se non è presente alcuna intersezione, verrà restituita una struttura Rectangle vuota.

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

Parametri

a
Rectangle

Rettangolo da intersecare.

b
Rectangle

Rettangolo da intersecare.

Restituisce

Rectangle che rappresenta l'intersezione di a e b.

Esempio

Nell'esempio di codice seguente vengono illustrati gli Intersectelementi e IsEmpty i IntersectsWith membri. Questo esempio deve essere usato con un Windows Form. Incollare questo codice in un modulo e chiamare questo metodo durante la gestione dell'evento del Paint modulo, passando e come PaintEventArgs.

private:
   void StaticRectangleIntersection( 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 ) )
      {
         Rectangle rectangle3 = Rectangle::Intersect( rectangle1, rectangle2 );
         if (  !rectangle3.IsEmpty )
         {
            e->Graphics->FillRectangle( Brushes::Green, rectangle3 );
         }
      }
   }
private void StaticRectangleIntersection(PaintEventArgs e)
{
    Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);
    Rectangle rectangle2 = new Rectangle(70, 20, 100, 200);
    Rectangle rectangle3 = new Rectangle();

    e.Graphics.DrawRectangle(Pens.Black, rectangle1);
    e.Graphics.DrawRectangle(Pens.Red, rectangle2);

    if (rectangle1.IntersectsWith(rectangle2))
    {
        rectangle3 = Rectangle.Intersect(rectangle1, rectangle2);
        if (!rectangle3.IsEmpty)
        {
            e.Graphics.FillRectangle(Brushes.Green, rectangle3);
        }
    }
}
Private Sub StaticRectangleIntersection(ByVal e As PaintEventArgs)
    Dim rectangle1 As New Rectangle(50, 50, 200, 100)
    Dim rectangle2 As New Rectangle(70, 20, 100, 200)
    Dim rectangle3 As New Rectangle

    e.Graphics.DrawRectangle(Pens.Black, rectangle1)
    e.Graphics.DrawRectangle(Pens.Red, rectangle2)

    If (rectangle1.IntersectsWith(rectangle2)) Then
        rectangle3 = Rectangle.Intersect(rectangle1, rectangle2)
        If Not rectangle3.IsEmpty Then
            e.Graphics.FillRectangle(Brushes.Green, rectangle3)
        End If
    End If
End Sub

Si applica a

Intersect(Rectangle)

Source:
Rectangle.cs
Source:
Rectangle.cs
Source:
Rectangle.cs

Sostituisce l'oggetto Rectangle con la sua intersezione con l'oggetto Rectangle specificato.

public:
 void Intersect(System::Drawing::Rectangle rect);
public void Intersect (System.Drawing.Rectangle rect);
member this.Intersect : System.Drawing.Rectangle -> unit
Public Sub Intersect (rect As Rectangle)

Parametri

rect
Rectangle

Rectangle di intersezione.

Esempio

Nell'esempio di codice seguente vengono illustrati gli Intersectelementi e IsEmpty i IntersectsWith membri. Questo esempio deve essere usato con un Windows Form. Incollare questo codice in un modulo e chiamare questo metodo durante la gestione dell'evento del Paint modulo, passando e come 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

Si applica a