Graphics.ResetClip 方法

定义

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

public:
 void ResetClip();
public void ResetClip ();
member this.ResetClip : unit -> unit
Public Sub ResetClip ()

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

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

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

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

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

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

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

public:
   void IntersectClipRectangleF2( PaintEventArgs^ e )
   {
      // Set clipping region.
      Rectangle clipRect = Rectangle(0,0,200,200);
      e->Graphics->SetClip( clipRect );

      // Update clipping region to intersection of
      // existing region with specified rectangle.
      RectangleF intersectRectF = RectangleF(100.0F,100.0F,200.0F,200.0F);
      e->Graphics->IntersectClip( intersectRectF );

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

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

      // Draw clipRect and intersectRect to screen.
      e->Graphics->DrawRectangle( gcnew Pen( Color::Black ), clipRect );
      e->Graphics->DrawRectangle( gcnew Pen( Color::Red ), Rectangle::Round( intersectRectF ) );
   }
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));
}
Private Sub IntersectClipRectangleF2(ByVal e As PaintEventArgs)

    ' Set clipping region.
    Dim clipRect As New Rectangle(0, 0, 200, 200)
    e.Graphics.SetClip(clipRect)

    ' Update clipping region to intersection of

    ' existing region with specified rectangle.
    Dim intersectRectF As 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))
End Sub

注解

当 的剪裁区域 Graphics 无限时,不会剪裁此 Graphics 绘制的项。

适用于