共用方式為


Rectangle.Intersect 方法

定義

判斷 Rectangle 結構,該結構代表兩個矩形的交集。

多載

Intersect(Rectangle, Rectangle)

傳回第三個 Rectangle 結構,該結構代表其他兩個 Rectangle 結構的交集。 如果沒有交集,則會傳回空的 Rectangle

Intersect(Rectangle)

以這個 Rectangle 和指定 Rectangle 的交集,來取代其本身。

Intersect(Rectangle, Rectangle)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
Rectangle.cs

傳回第三個 Rectangle 結構,該結構代表其他兩個 Rectangle 結構的交集。 如果沒有交集,則會傳回空的 Rectangle

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

參數

a
Rectangle

要交集的矩形。

b
Rectangle

要交集的矩形。

傳回

Rectangle,代表 ab 的交集。

範例

下列程式代碼範例示範 IntersectIsEmptyIntersectsWith 成員。 此範例應該與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件 Paint 時呼叫此方法,並 e 傳遞為 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

適用於

Intersect(Rectangle)

來源:
Rectangle.cs
來源:
Rectangle.cs
來源:
Rectangle.cs

以這個 Rectangle 和指定 Rectangle 的交集,來取代其本身。

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)

參數

rect
Rectangle

要相交的 Rectangle

範例

下列程式代碼範例示範 IntersectIsEmptyIntersectsWith 成員。 此範例應該與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件 Paint 時呼叫此方法,並 e 傳遞為 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

適用於