次の方法で共有


RectangleF.Intersect メソッド (RectangleF, RectangleF)

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

Overloads Public Shared Function Intersect( _
   ByVal a As RectangleF, _   ByVal b As RectangleF _) As RectangleF
[C#]
public static RectangleF Intersect(RectangleFa,RectangleFb);
[C++]
public: static RectangleF Intersect(RectangleFa,RectangleFb);
[JScript]
public static function Intersect(
   a : RectangleF,b : RectangleF) : RectangleF;

パラメータ

  • a
    交差する四角形。
  • b
    交差する四角形。

戻り値

指定の 2 つの四角形の重複領域サイズを表す 3 番目の RectangleF 構造体。

使用例

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

 
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# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

RectangleF 構造体 | RectangleF メンバ | System.Drawing 名前空間 | RectangleF.Intersect オーバーロードの一覧