Region.Complement Method

Definition

Updates this Region to the portion of the specified RectangleF structure that does not intersect with this Region.

Overloads

Complement(Region)

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

Complement(RectangleF)

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

Complement(GraphicsPath)

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

Complement(Rectangle)

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

Complement(Region)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

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

public void Complement (System.Drawing.Region region);

Parameters

region
Region

The Region object to complement this Region object.

Exceptions

region is null.

Examples

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 = new 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 = new Rectangle(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red, complementRect);
             
    // Create a region from the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Create a complement region.
    Region complementRegion = new Region(complementRect);
             
    // Get the complement of myRegion when combined with
             
    // complementRegion.
    myRegion.Complement(complementRegion);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}

Applies to

.NET 9 (package-provided) og andre versioner
Produkt Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Complement(RectangleF)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

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

public void Complement (System.Drawing.RectangleF rect);

Parameters

rect
RectangleF

The RectangleF structure to complement this Region.

Examples

The following code 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 a region using the first rectangle.

  • Gets the complement of that region combined with the second rectangle.

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

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

public void Complement_RectF_Example(PaintEventArgs e)
{
             
    // Create the first rectangle and draw it to the screen in black.
    Rectangle regionRect = new Rectangle(20, 20, 100, 100);
    e.Graphics.DrawRectangle(Pens.Black, regionRect);
             
    // Create the second rectangle and draw it to the screen in red.
    RectangleF complementRect = new RectangleF(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red,
        Rectangle.Round(complementRect));
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Get the complement of the region combined with the second
             
    // rectangle.
    myRegion.Complement(complementRect);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}

Applies to

.NET 9 (package-provided) og andre versioner
Produkt Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Complement(GraphicsPath)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

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

public void Complement (System.Drawing.Drawing2D.GraphicsPath path);

Parameters

path
GraphicsPath

The GraphicsPath to complement this Region.

Exceptions

path is null.

Examples

The following code 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 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 = new 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 = new Rectangle(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red, complementRect);
             
    // Create a graphics path and add the second rectangle to it.
    GraphicsPath complementPath = new GraphicsPath();
    complementPath.AddRectangle(complementRect);
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Get the complement of myRegion when combined with
             
    // complementPath.
    myRegion.Complement(complementPath);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}

Applies to

.NET 9 (package-provided) og andre versioner
Produkt Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Complement(Rectangle)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

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

public void Complement (System.Drawing.Rectangle rect);

Parameters

rect
Rectangle

The Rectangle structure to complement this Region.

Examples

For an example, see the Complement(RectangleF) method.

Applies to

.NET 9 (package-provided) og andre versioner
Produkt Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9