Region::Complement Method (Region^)
Updates this Region to contain the portion of the specified Region that does not intersect with this Region.
Assembly: System.Drawing (in System.Drawing.dll)
| Exception | Condition |
|---|---|
| ArgumentNullException | region is null. |
The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:
Creates a rectangle and draws it to the screen in black
Creates a second rectangle that intersects with the first and draws it to the screen in red.
Creates one region using the first rectangle and creates a second region using the second rectangle.
Gets the complement of that first region when combined with the second region.
Fills the complement area with blue and draws it to the screen.
Notice that the area of the second region that does not intersect with the first region is colored blue.
public: void Complement_Region_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. Rectangle complementRect = Rectangle(90,30,100,100); e->Graphics->DrawRectangle( Pens::Red, complementRect ); // Create a region from the first rectangle. System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect ); // Create a complement region. System::Drawing::Region^ complementRegion = gcnew System::Drawing::Region( complementRect ); // Get the complement of myRegion when combined with // complementRegion. myRegion->Complement( complementRegion ); // Fill the complement area with blue. SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue ); e->Graphics->FillRegion( myBrush, myRegion ); }
Available since 1.1