RectangleF.Union メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Dim a As RectangleF Dim b As RectangleF Dim returnValue As RectangleF returnValue = RectangleF.Union(a, b)
戻り値
和集合を形成する 2 つの四角形の両方が含まれる 3 番目の RectangleF 構造体。
この例は、Windows フォームでの使用を意図してデザインされており、OnPaint のイベント オブジェクトである PaintEventArgs e が必要です。このコードでは、2 つの RectangleF を作成し、画面に黒および赤で描画します。描画するには Rectangle に変換する必要があります。そのため、このコードでは、Union メソッドを使用して 3 番目の RectangleF を作成し、これを Rectangle に変換し、画面に青で描画します。3 番目の (青の) 四角形は残りの 2 つの四角形を両方含めることができる最小の四角形となります。
Public Sub RectangleFUnionExample(ByVal 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
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); }
public: void RectangleFUnionExample( PaintEventArgs^ e ) { // Create two rectangles and draw them to the screen. RectangleF firstRectangleF = RectangleF(0,0,75,50); RectangleF secondRectangleF = 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 ); }
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.get_Graphics().DrawRectangle(Pens.get_Black(), firstRect); e.get_Graphics().DrawRectangle(Pens.get_Red(), secondRect); // Get the union rectangle. RectangleF unionRectangleF = RectangleF.Union(firstRectangleF, secondRectangleF); // Draw the unionRectangleF to the screen. Rectangle unionRect = Rectangle.Truncate(unionRectangleF); e.get_Graphics().DrawRectangle(Pens.get_Blue(), unionRect); } //RectangleFUnionExample
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- RectangleF.Union メソッドのページへのリンク