RectangleF.Intersect 方法

定义

确定表示两个矩形交集的 RectangleF 结构。

重载

Intersect(RectangleF)

将此 RectangleF 结构替换为自身的交集和指定的 RectangleF 结构。

Intersect(RectangleF, RectangleF)

返回一个 RectangleF 结构,该结构表示两个矩形的交集。 如果没有交集,则返回空 RectangleF

Intersect(RectangleF)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
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)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
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 窗体一起使用,它需要 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

适用于