RectangleF.Intersect 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
決定代表兩個矩形交集的 RectangleF 結構。
Intersect(RectangleF) |
將這個 RectangleF 結構取代為本身的交集和指定的 RectangleF 結構。 |
Intersect(RectangleF, RectangleF) |
傳回 RectangleF 結構,表示兩個矩形的交集。 如果沒有交集,則會傳回空的 RectangleF。 |
將這個 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
要交集的矩形。
適用於
.NET 9 及其他版本
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
傳回 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
參數
要交集的矩形。
要交集的矩形。
傳回
第三個 RectangleF 結構,其大小代表兩個指定矩形的重疊區域。
範例
此範例的設計目的是要與 Windows Forms 搭配使用,而且需要 PaintEventArgse
OnPaint 事件物件。 程序代碼會建立兩個 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
適用於
.NET 9 及其他版本
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |