Graphics.IntersectClip 方法

定義

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 Rectangle 結構。

多載

IntersectClip(Rectangle)

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 Rectangle 結構。

IntersectClip(RectangleF)

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 RectangleF 結構。

IntersectClip(Region)

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 Region

IntersectClip(Rectangle)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 Rectangle 結構。

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

參數

rect
Rectangle

Rectangle 結構與目前剪輯區域交集。

範例

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

  • 建立左上角為 (0, 0) 的矩形,並將裁剪區域設定為此矩形。

  • 建立左上角為 (100, 100) 的第二個矩形,並將裁剪區域設定為此矩形的交集和目前的裁剪區域(第一個矩形)。

  • 以純藍色筆刷填滿包含上述兩個矩形的大型矩形。

  • 將裁剪區域重設為無限。

  • 在兩個裁剪區域周圍繪製矩形。 它會針對第一個裁剪矩形使用黑色畫筆,第二個裁剪區域的紅色畫筆。

結果是只有兩個矩形的交集填滿藍色。

C#
private void IntersectClipRectangle(PaintEventArgs e)
{

    // Set clipping region.
    Rectangle clipRect = new Rectangle(0, 0, 200, 200);
    e.Graphics.SetClip(clipRect);

    // Update clipping region to intersection of

    // existing region with specified rectangle.
    Rectangle intersectRect = new Rectangle(100, 100, 200, 200);
    e.Graphics.IntersectClip(intersectRect);

    // Fill rectangle to demonstrate effective clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 500, 500);

    // Reset clipping region to infinite.
    e.Graphics.ResetClip();

    // Draw clipRect and intersectRect to screen.
    e.Graphics.DrawRectangle(new Pen(Color.Black), clipRect);
    e.Graphics.DrawRectangle(new Pen(Color.Red), intersectRect);
}

備註

這個方法會指派給這個 的 Clip 屬性,Graphics 目前剪輯區域與 rect 參數所指定之矩形交集所代表的區域。

適用於

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

IntersectClip(RectangleF)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 RectangleF 結構。

C#
public void IntersectClip(System.Drawing.RectangleF rect);

參數

rect
RectangleF

RectangleF 結構與目前剪輯區域交集。

範例

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

  • 建立左上角為 (0, 0) 的矩形,並將裁剪區域設定為此矩形。

  • 建立左上角為 (100, 100) 的第二個矩形,並將裁剪區域設定為此矩形的交集和目前的裁剪區域(第一個矩形)。

  • 以純藍色筆刷填滿包含上述兩個矩形的大型矩形。

  • 將裁剪區域重設為無限。

  • 在兩個裁剪區域周圍繪製矩形。 它會針對第一個裁剪矩形使用黑色畫筆,第二個裁剪區域的紅色畫筆。

結果是只有兩個矩形的交集填滿藍色。

C#
private void IntersectClipRectangleF1(PaintEventArgs e)
{

    // Set clipping region.
    Rectangle clipRect = new Rectangle(0, 0, 200, 200);
    e.Graphics.SetClip(clipRect);

    // Update clipping region to intersection of

    // existing region with specified rectangle.
    RectangleF intersectRectF = new RectangleF(100.0F, 100.0F, 200.0F, 200.0F);
    e.Graphics.IntersectClip(intersectRectF);

    // Fill rectangle to demonstrate effective clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 500, 500);

    // Reset clipping region to infinite.
    e.Graphics.ResetClip();

    // Draw clipRect and intersectRect to screen.
    e.Graphics.DrawRectangle(new Pen(Color.Black), clipRect);
    e.Graphics.DrawRectangle(new Pen(Color.Red), Rectangle.Round(intersectRectF));
}

備註

這個方法會指派給這個 的 Clip 屬性,Graphics 目前剪輯區域與 rect 參數所指定之矩形交集所代表的區域。

適用於

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

IntersectClip(Region)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

將這個 Graphics 的剪輯區域更新為目前剪輯區域的交集和指定的 Region

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

參數

region
Region

Region 與目前區域交集。

範例

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

  • 建立左上角為 (0, 0) 的矩形。

  • 建立區域並將它設定為矩形,並將裁剪區域設定為這個區域。

  • 建立左上角為 (100, 100) 的第二個矩形。

  • 建立區域並將它設定為第二個矩形,並使用結合模式的 Replace,將裁剪區域設定為這個區域的交集和目前裁剪區域 (第一個矩形)。

  • 以純藍色筆刷填滿包含上述兩個區域的大型矩形。

  • 將裁剪區域重設為無限。

  • 在兩個裁剪區域周圍繪製矩形。 它會針對第一個裁剪區域使用黑色畫筆,第二個裁剪區域的紅色畫筆。

結果是只有兩個區域的交集會填滿藍色。

C#
private void IntersectClipRegion(PaintEventArgs e)
{

    // Set clipping region.
    Rectangle clipRect = new Rectangle(0, 0, 200, 200);
    Region clipRegion = new Region(clipRect);
    e.Graphics.SetClip(clipRegion, CombineMode.Replace);

    // Update clipping region to intersection of

    // existing region with specified rectangle.
    Rectangle intersectRect = new Rectangle(100, 100, 200, 200);
    Region intersectRegion = new Region(intersectRect);
    e.Graphics.IntersectClip(intersectRegion);

    // Fill rectangle to demonstrate effective clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 500, 500);

    // Reset clipping region to infinite.
    e.Graphics.ResetClip();

    // Draw clipRect and intersectRect to screen.
    e.Graphics.DrawRectangle(new Pen(Color.Black), clipRect);
    e.Graphics.DrawRectangle(new Pen(Color.Red), intersectRect);
}

備註

這個方法會指派給這個 的 Clip 屬性,Graphics 目前剪輯區域與 region 參數所指定區域交集所代表的區域。

適用於

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