次の方法で共有


RectangleF.Intersect メソッド

2 つの四角形の交差部分を表す RectangleF 構造体を返します。交差部分がない場合は、null が返されます。

オーバーロードの一覧

この RectangleF 構造体を、その構造体と指定の RectangleF 構造体の交差部分に置き換えます。

[Visual Basic] Overloads Public Sub Intersect(RectangleF)

[C#] public void Intersect(RectangleF);

[C++] public: void Intersect(RectangleF);

[JScript] public function Intersect(RectangleF);

2 つの四角形の交差部分を表す RectangleF 構造体を返します。交差部分がない場合は、null が返されます。

[Visual Basic] Overloads Public Shared Function Intersect(RectangleF, RectangleF) As RectangleF

[C#] public static RectangleF Intersect(RectangleF, RectangleF);

[C++] public: static RectangleF Intersect(RectangleF, RectangleF);

[JScript] public static function Intersect(RectangleF, RectangleF) : RectangleF;

使用例

[Visual Basic, C#] この例は、Windows フォームでの使用を意図してデザインされており、OnPaint のイベント オブジェクトである PaintEventArgs e が必要です。このコードでは、2 つの RectangleF を作成し、画面に黒および赤で描画します。描画するには Rectangle に変換する必要があります。そのため、このコードでは、 Intersect メソッドを使用して 3 番目の RectangleF を作成し、これを Rectangle に変換し、画面に青で描画します。3 番目の (青の) 四角形は残りの 2 つの四角形の重複領域となります。

[Visual Basic, C#] メモ   ここでは、Intersect のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Public Sub RectangleFIntersectExample(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
        
[C#] 
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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

RectangleF 構造体 | RectangleF メンバ | System.Drawing 名前空間