共用方式為


RectangleF.Intersect 方法

定義

決定代表兩個矩形交集的 RectangleF 結構。

多載

Intersect(RectangleF)

將這個 RectangleF 結構取代為本身的交集和指定的 RectangleF 結構。

Intersect(RectangleF, RectangleF)

傳回 RectangleF 結構,表示兩個矩形的交集。 如果沒有交集,則會傳回空的 RectangleF

Intersect(RectangleF)

來源:
RectangleF.cs
來源:
RectangleF.cs
來源:
RectangleF.cs

將這個 RectangleF 結構取代為本身的交集和指定的 RectangleF 結構。

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

要交集的矩形。

適用於

Intersect(RectangleF, RectangleF)

來源:
RectangleF.cs
來源:
RectangleF.cs
來源:
RectangleF.cs

傳回 RectangleF 結構,表示兩個矩形的交集。 如果沒有交集,則會傳回空的 RectangleF

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

要交集的矩形。

b
RectangleF

要交集的矩形。

傳回

第三個 RectangleF 結構,其大小代表兩個指定矩形的重疊區域。

範例

此範例的設計目的是要與 Windows Forms 搭配使用,而且需要 PaintEventArgseOnPaint 事件物件。 程序代碼會建立兩個 RectangleF 物件,並以黑色和紅色繪製到畫面。 請注意,它們必須轉換成 Rectangle 物件以供繪製之用。 然後程式代碼會使用 Intersect 方法建立第三個 RectangleF,將它轉換成 Rectangle,並以藍色繪製到螢幕。 請注意,第三個 (藍色) 矩形是其他兩個矩形重疊的區域:

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

適用於