RectangleF.Intersect 方法

定義

判斷 RectangleF 結構,該結構代表兩個矩形的交集。Determines the RectangleF structure that represents the intersection of two rectangles.

多載

Intersect(RectangleF, RectangleF)

傳回 RectangleF 結構,這個結構表示兩個矩形的交集。Returns a RectangleF structure that represents the intersection of two rectangles. 如果沒有交集,則會傳回空的 RectangleFIf there is no intersection, and empty RectangleF is returned.

Intersect(RectangleF)

將此 RectangleF 結構取代為它本身與指定 RectangleF 結構的交集。Replaces this RectangleF structure with the intersection of itself and the specified RectangleF structure.

Intersect(RectangleF, RectangleF)

傳回 RectangleF 結構,這個結構表示兩個矩形的交集。Returns a RectangleF structure that represents the intersection of two rectangles. 如果沒有交集,則會傳回空的 RectangleFIf there is no intersection, and empty RectangleF is returned.

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

參數

a
RectangleF

要交集的矩形。A rectangle to intersect.

b
RectangleF

要交集的矩形。A rectangle to intersect.

傳回

RectangleF

第三個 RectangleF 結構,其大小表示兩個指定矩形的重疊區域。A third RectangleF structure the size of which represents the overlapped area of the two specified rectangles.

範例

這個範例是設計來搭配 Windows Forms 使用,而且它需要 PaintEventArgs e OnPaint 事件物件。This example is designed for use with Windows Forms, and it requires PaintEventArgse, an OnPaint event object. 程式碼會建立兩個 RectangleF 物件,並以黑色和紅色將它們繪製到螢幕上。The code creates two RectangleF objects and draws them to the screen in black and red. 請注意,它們必須轉換成 Rectangle 物件,以供繪製之用。Notice that they have to be converted to Rectangle objects for drawing purposes. 然後,程式碼會使用方法建立第三個 RectangleF Intersect ,將它轉換成 Rectangle ,並將它繪製到藍色的螢幕上。Then the code creates a third RectangleF using the Intersect method, converts it to a Rectangle, and draws it to the screen in blue. 請注意,第三個 (藍色) 矩形是其他兩個矩形的重迭區域:Notice the third (blue) rectangle is the area of overlap of the other two rectangles:

public:
   void RectangleFIntersectExample( PaintEventArgs^ e )
   {
      // Create two rectangles.
      RectangleF firstRectangleF = RectangleF(0,0,75,50);
      RectangleF secondRectangleF = RectangleF(50,20,50,50);

      // Convert the RectangleF structures to Rectangle structures and draw them to the
      // screen.
      Rectangle firstRect = Rectangle::Truncate( firstRectangleF );
      Rectangle secondRect = Rectangle::Truncate( secondRectangleF );
      e->Graphics->DrawRectangle( Pens::Black, firstRect );
      e->Graphics->DrawRectangle( Pens::Red, secondRect );

      // Get the intersection.
      RectangleF intersectRectangleF = RectangleF::Intersect( firstRectangleF, secondRectangleF );

      // Draw the intersectRectangleF to the screen.
      Rectangle intersectRect = Rectangle::Truncate( intersectRectangleF );
      e->Graphics->DrawRectangle( Pens::Blue, intersectRect );
   }
public void RectangleFIntersectExample(PaintEventArgs e)
{
             
    // Create two rectangles.
    RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50);
    RectangleF secondRectangleF = new RectangleF(50, 20, 50, 50);
             
    // Convert the RectangleF structures to Rectangle structures and draw them to the
             
    // screen.
    Rectangle firstRect = Rectangle.Truncate(firstRectangleF);
    Rectangle secondRect = Rectangle.Truncate(secondRectangleF);
    e.Graphics.DrawRectangle(Pens.Black, firstRect);
    e.Graphics.DrawRectangle(Pens.Red, secondRect);
             
    // Get the intersection.
    RectangleF intersectRectangleF =
        RectangleF.Intersect(firstRectangleF,
        secondRectangleF);
             
    // Draw the intersectRectangleF to the screen.
    Rectangle intersectRect =
        Rectangle.Truncate(intersectRectangleF);
    e.Graphics.DrawRectangle(Pens.Blue, intersectRect);
}
Public Sub RectangleFIntersectExample(ByVal e As PaintEventArgs)

    ' Create two rectangles.
    Dim firstRectangleF As New RectangleF(0, 0, 75, 50)
    Dim secondRectangleF As New RectangleF(50, 20, 50, 50)

    ' Convert the RectangleF structures to Rectangle structures and

    ' draw them to the screen.
    Dim firstRect As Rectangle = Rectangle.Truncate(firstRectangleF)
    Dim secondRect As Rectangle = Rectangle.Truncate(secondRectangleF)
    e.Graphics.DrawRectangle(Pens.Black, firstRect)
    e.Graphics.DrawRectangle(Pens.Red, secondRect)

    ' Get the intersection.
    Dim intersectRectangleF As RectangleF = _
    RectangleF.Intersect(firstRectangleF, secondRectangleF)

    ' Draw the intersectRectangleF to the screen.
    Dim intersectRect As Rectangle = _
    Rectangle.Truncate(intersectRectangleF)
    e.Graphics.DrawRectangle(Pens.Blue, intersectRect)
End Sub

適用於

Intersect(RectangleF)

將此 RectangleF 結構取代為它本身與指定 RectangleF 結構的交集。Replaces this RectangleF structure with the intersection of itself and the specified RectangleF structure.

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

參數

rect
RectangleF

要交集的矩形。The rectangle to intersect.

適用於