Region::Union Method (RectangleF)

 

Updates this Region to the union of itself and the specified RectangleF structure.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public:
void Union(
	RectangleF rect
)

Parameters

rect
Type: System.Drawing::RectangleF

The RectangleF structure to unite with this Region.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse. The code performs the following actions:

  • Creates the first rectangle and draws it to the screen in black.

  • Creates a second rectangle and draws it to the screen in red.

  • Creates a region using the first rectangle.

  • Gets the area of union for myRegion when combined with complementRect.

  • Fills the fills the area of union with blue and draws it to the screen.

Notice that both rectangles are filled with blue, including the area of overlap.

void Union_RectF_Example( PaintEventArgs^ e )
{
   // Create the first rectangle and draw it to the screen in black.
   Rectangle regionRect = Rectangle(20,20,100,100);
   e->Graphics->DrawRectangle( Pens::Black, regionRect );

   // create the second rectangle and draw it to the screen in red.
   RectangleF unionRect = RectangleF(90,30,100,100);
   e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( unionRect ) );

   // Create a region using the first rectangle.
   System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );

   // Get the area of union for myRegion when combined with
   // complementRect.
   myRegion->Union( unionRect );

   // Fill the union area of myRegion with blue.
   SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
   e->Graphics->FillRegion( myBrush, myRegion );
}

.NET Framework
Available since 1.1
Return to top
Show: