Region.Complement 方法

定义

将此 Region 更新为指定的 RectangleF 结构中与此 Region 不相交的部分。

重载

Complement(Region)

更新此 Region 以包含与此 Region 不相交的指定的 Region 的那部分。

Complement(RectangleF)

更新此 Region,以包含指定的 RectangleF 结构中与此 Region 不相交的部分。

Complement(GraphicsPath)

更新此 Region 以包含与此 Region 不相交的指定的 GraphicsPath 的那部分。

Complement(Rectangle)

更新此 Region,以包含指定的 Rectangle 结构中与此 Region 不相交的部分。

Complement(Region)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

更新此 Region 以包含与此 Region 不相交的指定的 Region 的那部分。

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

参数

region
Region

要对此 Region 对象进行补充的 Region 对象。

例外

regionnull

示例

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

  • 创建一个矩形并将其绘制到黑色屏幕

  • 创建与第一个相交的第二个矩形,并将其绘制到红色屏幕。

  • 使用第一个矩形创建一个区域,并使用第二个矩形创建第二个区域。

  • 获取与第二个区域组合时第一个区域的补充。

  • 用蓝色填充补码区域,并将其绘制到屏幕上。

请注意,第二个区域不与第一个区域相交的区域为蓝色。

public:
   void Complement_Region_Example( PaintEventArgs^ e )
   {
      // Create the first rectangle and draw it to the screen in black.
      Rectangle regionRect = Rectangle(20,20,100,100);
      e->Graphics->DrawRectangle( Pens::Black, regionRect );

      // Create the second rectangle and draw it to the screen in red.
      Rectangle complementRect = Rectangle(90,30,100,100);
      e->Graphics->DrawRectangle( Pens::Red, complementRect );

      // Create a region from the first rectangle.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );

      // Create a complement region.
      System::Drawing::Region^ complementRegion = gcnew System::Drawing::Region( complementRect );

      // Get the complement of myRegion when combined with
      // complementRegion.
      myRegion->Complement( complementRegion );

      // Fill the complement area with blue.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillRegion( myBrush, myRegion );
   }
public void Complement_Region_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.
    Rectangle complementRect = new Rectangle(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red, complementRect);
             
    // Create a region from the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Create a complement region.
    Region complementRegion = new Region(complementRect);
             
    // Get the complement of myRegion when combined with
             
    // complementRegion.
    myRegion.Complement(complementRegion);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Complement_Region_Example(ByVal e As PaintEventArgs)

    ' Create the first rectangle and draw it to the screen in black.
    Dim regionRect As New Rectangle(20, 20, 100, 100)
    e.Graphics.DrawRectangle(Pens.Black, regionRect)

    ' Create the second rectangle and draw it to the screen in red.
    Dim complementRect As New Rectangle(90, 30, 100, 100)
    e.Graphics.DrawRectangle(Pens.Red, complementRect)

    ' create a region from the first rectangle.
    Dim myRegion As New [Region](regionRect)

    ' Create a complement region.
    Dim complementRegion As New [Region](complementRect)

    ' Get the complement of myRegion when combined with
    ' complementRegion.
    myRegion.Complement(complementRegion)

    ' Fill the complement area with blue.
    Dim myBrush As New SolidBrush(Color.Blue)
    e.Graphics.FillRegion(myBrush, myRegion)
End Sub

适用于

Complement(RectangleF)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

更新此 Region,以包含指定的 RectangleF 结构中与此 Region 不相交的部分。

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

参数

rect
RectangleF

RectangleF 结构,它是对此 Region 的补充。

示例

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

  • 创建一个矩形并将其绘制到黑色屏幕。

  • 创建与第一个相交的第二个矩形,并将其绘制到红色屏幕。

  • 使用第一个矩形创建区域。

  • 获取该区域与第二个矩形的组合。

  • 用蓝色填充补码区域,并将其绘制到屏幕上。

请注意,不与该区域相交的第二个矩形的区域呈蓝色。

public:
   void Complement_RectF_Example( PaintEventArgs^ e )
   {
      // Create the first rectangle and draw it to the screen in black.
      Rectangle regionRect = 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 = RectangleF(90,30,100,100);
      e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( complementRect ) );

      // Create a region using the first rectangle.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );

      // Get the complement of the region combined with the second
      // rectangle.
      myRegion->Complement( complementRect );

      // Fill the complement area with blue.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillRegion( myBrush, myRegion );
   }
public void Complement_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 complement of the region combined with the second
             
    // rectangle.
    myRegion.Complement(complementRect);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Complement_RectF_Example(ByVal e As PaintEventArgs)

    ' Create the first rectangle and draw it to the screen in black.
    Dim regionRect As New Rectangle(20, 20, 100, 100)
    e.Graphics.DrawRectangle(Pens.Black, regionRect)

    ' Create the second rectangle and draw it to the screen in red.
    Dim complementRect As New RectangleF(90, 30, 100, 100)
    e.Graphics.DrawRectangle(Pens.Red, _
    Rectangle.Round(complementRect))

    ' Create a region using the first rectangle.
    Dim myRegion As New [Region](regionRect)

    ' Get the complement of the region combined with the second
    ' rectangle.
    myRegion.Complement(complementRect)

    ' Fill the complement area with blue.
    Dim myBrush As New SolidBrush(Color.Blue)
    e.Graphics.FillRegion(myBrush, myRegion)
End Sub

适用于

Complement(GraphicsPath)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

更新此 Region 以包含与此 Region 不相交的指定的 GraphicsPath 的那部分。

public:
 void Complement(System::Drawing::Drawing2D::GraphicsPath ^ path);
public void Complement (System.Drawing.Drawing2D.GraphicsPath path);
member this.Complement : System.Drawing.Drawing2D.GraphicsPath -> unit
Public Sub Complement (path As GraphicsPath)

参数

path
GraphicsPath

要对此 Region 进行补充的 GraphicsPath

例外

pathnull

示例

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

  • 创建一个矩形并将其绘制到黑色屏幕。

  • 创建与第一个相交的第二个矩形,并将其绘制到红色屏幕。

  • 使用第一个矩形创建区域。

  • 创建 一个 GraphicsPath,并向其中添加第二个矩形。

  • 获取与 GraphicsPath组合时区域的补数。

  • 用蓝色填充补码区域,并将其绘制到屏幕上。

请注意,不与该区域相交的 GraphicsPath 的区域呈蓝色。

public:
   void Complement_Path_Example( PaintEventArgs^ e )
   {
      // Create the first rectangle and draw it to the screen in black.
      Rectangle regionRect = Rectangle(20,20,100,100);
      e->Graphics->DrawRectangle( Pens::Black, regionRect );

      // Create the second rectangle and draw it to the screen in red.
      Rectangle complementRect = Rectangle(90,30,100,100);
      e->Graphics->DrawRectangle( Pens::Red, complementRect );

      // Create a graphics path and add the second rectangle to it.
      GraphicsPath^ complementPath = gcnew GraphicsPath;
      complementPath->AddRectangle( complementRect );

      // Create a region using the first rectangle.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );

      // Get the complement of myRegion when combined with
      // complementPath.
      myRegion->Complement( complementPath );

      // Fill the complement area with blue.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillRegion( myBrush, myRegion );
   }
public void Complement_Path_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.
    Rectangle complementRect = new Rectangle(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red, complementRect);
             
    // Create a graphics path and add the second rectangle to it.
    GraphicsPath complementPath = new GraphicsPath();
    complementPath.AddRectangle(complementRect);
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Get the complement of myRegion when combined with
             
    // complementPath.
    myRegion.Complement(complementPath);
             
    // Fill the complement area with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Complement_Path_Example(ByVal e As PaintEventArgs)

    ' Create the first rectangle and draw it to the screen in black.
    Dim regionRect As New Rectangle(20, 20, 100, 100)
    e.Graphics.DrawRectangle(Pens.Black, regionRect)

    ' Create the second rectangle and draw it to the screen in red.
    Dim complementRect As New Rectangle(90, 30, 100, 100)
    e.Graphics.DrawRectangle(Pens.Red, complementRect)

    ' Create a graphics path and add the second rectangle to it.
    Dim complementPath As New GraphicsPath
    complementPath.AddRectangle(complementRect)

    ' Create a region using the first rectangle.
    Dim myRegion As New [Region](regionRect)

    ' Get the complement of myRegion when combined with
    ' complementPath.
    myRegion.Complement(complementPath)

    ' Fill the complement area with blue.
    Dim myBrush As New SolidBrush(Color.Blue)
    e.Graphics.FillRegion(myBrush, myRegion)
End Sub

适用于

Complement(Rectangle)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

更新此 Region,以包含指定的 Rectangle 结构中与此 Region 不相交的部分。

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

参数

rect
Rectangle

Rectangle 结构,它是对此 Region 的补充。

示例

有关示例,请参阅 Complement(RectangleF) 方法。

适用于