Graphics.ExcludeClip Method

Definition

Updates the clip region of this Graphics to exclude the area specified by a Rectangle structure.

Overloads

ExcludeClip(Region)

Updates the clip region of this Graphics to exclude the area specified by a Region.

ExcludeClip(Rectangle)

Updates the clip region of this Graphics to exclude the area specified by a Rectangle structure.

ExcludeClip(Region)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Updates the clip region of this Graphics to exclude the area specified by a Region.

C#
public void ExcludeClip(System.Drawing.Region region);

Parameters

region
Region

Region that specifies the region to exclude from the clip 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 100 pixel by 100 pixel rectangle whose upper-left corner is at the coordinate (100, 100).

  • Sets the clipping region to exclude the rectangle.

  • Fills a 300 pixel by 300 pixel rectangle whose upper-left corner is at the coordinate (0, 0) with a solid blue brush.

The result is a blue rectangle with a square area toward its lower-right corner missing.

C#
public void ExcludeClipRegion(PaintEventArgs e)
{
             
    // Create rectangle for region.
    Rectangle excludeRect = new Rectangle(100, 100, 200, 200);
             
    // Create region for exclusion.
    Region excludeRegion = new Region(excludeRect);
             
    // Set clipping region to exclude region.
    e.Graphics.ExcludeClip(excludeRegion);
             
    // Fill large rectangle to show clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 300, 300);
}

Remarks

This method excludes the area specified by the region parameter from the current clip region and assigns the resulting area to the Clip property of this Graphics.

Applies to

.NET 9 (package-provided) and other versions
Product 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

ExcludeClip(Rectangle)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Updates the clip region of this Graphics to exclude the area specified by a Rectangle structure.

C#
public void ExcludeClip(System.Drawing.Rectangle rect);

Parameters

rect
Rectangle

Rectangle structure that specifies the rectangle to exclude from the clip 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 100 pixel by 100 pixel rectangle whose upper-left corner is at the coordinate (100, 100).

  • Creates a region defined by the rectangle.

  • Sets the clipping region to exclude the rectangular region.

  • Fills a 300 pixel by 300 pixel rectangle whose upper-left corner is at the coordinate (0, 0) with a solid blue brush.

The result is a blue rectangle with a square region toward its lower-right corner missing.

C#
public void ExcludeClipRectangle(PaintEventArgs e)
{
             
    // Create rectangle for exclusion.
    Rectangle excludeRect = new Rectangle(100, 100, 200, 200);
             
    // Set clipping region to exclude rectangle.
    e.Graphics.ExcludeClip(excludeRect);
             
    // Fill large rectangle to show clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 300, 300);
}

Remarks

This method excludes the area specified by the rect parameter from the current clip region and assigns the resulting area to the Clip property of this Graphics.

Applies to

.NET 9 (package-provided) and other versions
Product 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