Region::Complement Method (GraphicsPath^)

 

Updates this Region to contain the portion of the specified GraphicsPath that does not intersect with this Region.

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

public:
void Complement(
	GraphicsPath^ path
)

Parameters

path
Type: System.Drawing.Drawing2D::GraphicsPath^

The GraphicsPath to complement this Region.

Exception Condition
ArgumentNullException

path is null.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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 a region using the first rectangle.

  • Creates a GraphicsPath, and adds the second rectangle to it.

  • Gets the complement of the region when combined with the GraphicsPath.

  • Fills the complement area with blue and draws it to the screen.

Notice that the area of the GraphicsPath that does not intersect with the region is colored blue.

public:
   void Complement_Path_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 graphics path and add the second rectangle to it.
      GraphicsPath^ complementPath = gcnew GraphicsPath;
      complementPath->AddRectangle( complementRect );

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

      // Get the complement of myRegion when combined with
      // complementPath.
      myRegion->Complement( complementPath );

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

.NET Framework
Available since 1.1
Return to top
Show: