Share via


Graphics.IntersectClip 方法

定义

将此 Graphics 的剪辑区域更新为当前剪辑区域与指定 Rectangle 结构的交集。

重载

IntersectClip(Rectangle)

将此 Graphics 的剪辑区域更新为当前剪辑区域与指定 Rectangle 结构的交集。

IntersectClip(RectangleF)

将此 Graphics 的剪辑区域更新为当前剪辑区域与指定 RectangleF 结构的交集。

IntersectClip(Region)

将此 Graphics 对象的剪辑区域更新为当前剪辑区域与指定 Region 的交集。

IntersectClip(Rectangle)

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

将此 Graphics 的剪辑区域更新为当前剪辑区域与指定 Rectangle 结构的交集。

public:
 void IntersectClip(System::Drawing::Rectangle rect);
public void IntersectClip (System.Drawing.Rectangle rect);
member this.IntersectClip : System.Drawing.Rectangle -> unit
Public Sub IntersectClip (rect As Rectangle)

参数

rect
Rectangle

与当前剪辑区域相交的 Rectangle 结构。

示例

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

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

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

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

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

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

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

public:
   void IntersectClipRectangle( 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.
      Rectangle intersectRect = Rectangle(100,100,200,200);
      e->Graphics->IntersectClip( intersectRect );

      // 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 ), intersectRect );
   }
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);
}
Private Sub IntersectClipRectangle(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 intersectRect As 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)
End Sub

注解

此方法将当前剪辑区域与 参数指定的rect矩形的交集表示的区域分配给ClipGraphics属性。

适用于

IntersectClip(RectangleF)

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

将此 Graphics 的剪辑区域更新为当前剪辑区域与指定 RectangleF 结构的交集。

public:
 void IntersectClip(System::Drawing::RectangleF rect);
public void IntersectClip (System.Drawing.RectangleF rect);
member this.IntersectClip : System.Drawing.RectangleF -> unit
Public Sub IntersectClip (rect As RectangleF)

参数

rect
RectangleF

与当前剪辑区域相交的 RectangleF 结构。

示例

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

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

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

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

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

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

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

public:
   void IntersectClipRectangleF1( 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 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));
}
Private Sub IntersectClipRectangleF1(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

注解

此方法将当前剪辑区域与 参数指定的rect矩形的交集表示的区域分配给ClipGraphics属性。

适用于

IntersectClip(Region)

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

将此 Graphics 对象的剪辑区域更新为当前剪辑区域与指定 Region 的交集。

public:
 void IntersectClip(System::Drawing::Region ^ region);
public void IntersectClip (System.Drawing.Region region);
member this.IntersectClip : System.Drawing.Region -> unit
Public Sub IntersectClip (region As Region)

参数

region
Region

要与当前区域交叉的 Region

示例

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

  • 创建左上角为 (0, 0) 的矩形。

  • 创建一个区域并将其设置为矩形,并将剪切区域设置为该区域。

  • 创建第二个矩形,左上角为 (100, 100) 。

  • 创建一个区域并将其设置为第二个矩形,并将剪切区域设置为此区域与当前剪切区域的交集, (第一个矩形) 使用 组合模式 Replace

  • 用纯蓝色画笔填充一个大矩形,该矩形包含前面的两个区域。

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

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

结果是只有两个区域的交集填充蓝色。

public:
   void IntersectClipRegion( PaintEventArgs^ e )
   {
      // Set clipping region.
      Rectangle clipRect = Rectangle(0,0,200,200);
      System::Drawing::Region^ clipRegion = gcnew System::Drawing::Region( clipRect );
      e->Graphics->SetClip( clipRegion, CombineMode::Replace );

      // Update clipping region to intersection of
      // existing region with specified rectangle.
      Rectangle intersectRect = Rectangle(100,100,200,200);
      System::Drawing::Region^ intersectRegion = gcnew System::Drawing::Region( intersectRect );
      e->Graphics->IntersectClip( intersectRegion );

      // 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 ), intersectRect );
   }
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);
}
Private Sub IntersectClipRegion(ByVal e As PaintEventArgs)

    ' Set clipping region.
    Dim clipRect As New Rectangle(0, 0, 200, 200)
    Dim clipRegion As New [Region](clipRect)
    e.Graphics.SetClip(clipRegion, CombineMode.Replace)

    ' Update clipping region to intersection of

    ' existing region with specified rectangle.
    Dim intersectRect As New Rectangle(100, 100, 200, 200)
    Dim intersectRegion As 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)
End Sub

注解

此方法将当前剪辑区域与 参数指定的region区域的交集表示的区域分配给ClipGraphics属性。

适用于