Region.Exclude 方法

定義

將此 Region 更新為其內部部分,但未與指定的 Rectangle 結構交集。

多載

Exclude(Region)

更新此 Region,只包含其內部部分,但未與指定的 Region相交。

Exclude(GraphicsPath)

更新此 Region,只包含其內部部分,但未與指定的 GraphicsPath相交。

Exclude(Rectangle)

更新此 Region,只包含其內部與指定之 Rectangle 結構不相交的部分。

Exclude(RectangleF)

更新此 Region,只包含其內部與指定之 RectangleF 結構不相交的部分。

Exclude(Region)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此 Region,只包含其內部部分,但未與指定的 Region相交。

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

參數

region
Region

要從這個 Region排除的 Region

例外狀況

region null

範例

如需程式代碼範例,請參閱 Exclude(RectangleF)Complement(Region) 方法。

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Exclude(GraphicsPath)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此 Region,只包含其內部部分,但未與指定的 GraphicsPath相交。

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

參數

path
GraphicsPath

要從這個 Region排除的 GraphicsPath

例外狀況

path null

範例

下列程式代碼範例示範 Region 建構函式和 ExcludeDispose 方法。

此範例的設計目的是要與 Windows Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的 Paint 事件時呼叫 FillRegionExcludingPath 方法,並將 e 傳遞為 PaintEventArgs

private void FillRegionExcludingPath(PaintEventArgs e)
{

    // Create the region using a rectangle.
    Region myRegion = new Region(new Rectangle(20, 20, 100, 100));

    // Create the GraphicsPath.
    System.Drawing.Drawing2D.GraphicsPath path = 
        new System.Drawing.Drawing2D.GraphicsPath();

    // Add a circle to the graphics path.
    path.AddEllipse(50, 50, 25, 25);

    // Exclude the circle from the region.
    myRegion.Exclude(path);

    // Retrieve a Graphics object from the form.
    Graphics formGraphics = e.Graphics;

    // Fill the region in blue.
    formGraphics.FillRegion(Brushes.Blue, myRegion);

    // Dispose of the path and region objects.
    path.Dispose();
    myRegion.Dispose();
}

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Exclude(Rectangle)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此 Region,只包含其內部與指定之 Rectangle 結構不相交的部分。

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

參數

rect
Rectangle

要從這個 Region中排除的 Rectangle 結構。

範例

如需程式代碼範例,請參閱 Exclude(RectangleF) 方法。

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Exclude(RectangleF)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此 Region,只包含其內部與指定之 RectangleF 結構不相交的部分。

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

參數

rect
RectangleF

要從這個 Region中排除的 RectangleF 結構。

範例

下列範例的設計目的是要與 Windows Forms 搭配使用,而且需要 PaintEventArgse,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:

  • 建立矩形,並將它繪製到黑色的畫面

  • 建立第二個矩形,與第一個矩形交集,並以紅色繪製到畫面。

  • 使用第一個矩形建立區域。

  • 當與第二個矩形結合時,取得區域的非排除區域。

  • 以藍色填滿非隔離區域,並將它繪製到螢幕。

請注意,未與矩形交集的區域區域會以藍色表示。

public void Exclude_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 nonexcluded area of myRegion when combined with
             
    // complementRect.
    myRegion.Exclude(complementRect);
             
    // Fill the nonexcluded area of myRegion with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9