次の方法で共有


RectangleF.Union メソッド

和集合を形成する 2 つの四角形の両方を含めることができる最小の 3 番目の四角形を作成します。

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

パラメータ

  • a
    結合する四角形。
  • b
    結合する四角形。

戻り値

和集合を形成する 2 つの四角形の両方が含まれる 3 番目の RectangleF 構造体。

使用例

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

 
Public Sub RectangleFUnionExample(e As PaintEventArgs)
' Create two rectangles and draw them to the screen.
Dim firstRectangleF As New RectangleF(0, 0, 75, 50)
Dim secondRectangleF As New RectangleF(100, 100, 20, 20)
' 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 union rectangle.
Dim unionRectangleF As RectangleF = _
RectangleF.Union(firstRectangleF, secondRectangleF)
' Draw the unionRectangleF to the screen.
Dim unionRect As Rectangle = Rectangle.Truncate(unionRectangleF)
e.Graphics.DrawRectangle(Pens.Blue, unionRect)
End Sub
        
[C#] 
public void RectangleFUnionExample(PaintEventArgs e)
{
// Create two rectangles and draw them to the screen.
RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50);
RectangleF secondRectangleF = new RectangleF(100, 100, 20, 20);
// 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 union rectangle.
RectangleF unionRectangleF = RectangleF.Union(firstRectangleF,
secondRectangleF);
// Draw the unionRectangleF to the screen.
Rectangle unionRect = Rectangle.Truncate(unionRectangleF);
e.Graphics.DrawRectangle(Pens.Blue, unionRect);
}
        

[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 名前空間