Graphics.ResetClip 方法

定义

将此 Graphics 的剪辑区域重置为无限区域。

C#
public void ResetClip();

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建左上角为 (0, 0) 的矩形,并将剪辑区域设置为此矩形。

  • 创建一个左上角为 (100, 100) 的第二个矩形,并将剪辑区域设置为此矩形的交集和当前剪辑区域(第一个矩形)。

  • 用纯蓝色画笔填充包含前两个矩形的大型矩形。

  • 将剪辑区域重置为无限。

  • 在两个剪裁区域周围绘制矩形;它为第一个剪裁矩形使用黑色笔,为第二个剪辑区域使用红色笔。

结果是,只有两个矩形的交集填充有蓝色。

C#
private void IntersectClipRectangleF2(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));
}

注解

Graphics 的剪辑区域无限时,不会剪切此 Graphics 绘制的项目。

适用于

产品 版本
.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