Region.Exclude 方法

定义

将其 Region 更新为其内部不与指定 Rectangle 结构相交的部分。

重载

名称 说明
Exclude(Region)

更新此项 Region 以仅包含其内部不与指定 Region相交的部分。

Exclude(GraphicsPath)

更新此项 Region 以仅包含其内部不与指定 GraphicsPath相交的部分。

Exclude(Rectangle)

更新此项 Region 以仅包含其内部不与指定 Rectangle 结构相交的部分。

Exclude(RectangleF)

更新此项 Region 以仅包含其内部不与指定 RectangleF 结构相交的部分。

Exclude(Region)

更新此项 Region 以仅包含其内部不与指定 Region相交的部分。

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

参数

region
Region

Region从中排除。Region

例外

regionnull

示例

有关代码示例,请参阅 Exclude(RectangleF)Complement(Region) 方法。

适用于

Exclude(GraphicsPath)

更新此项 Region 以仅包含其内部不与指定 GraphicsPath相交的部分。

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

参数

path
GraphicsPath

GraphicsPath从中排除。Region

例外

pathnull

示例

下面的代码示例演示 Region 构造函数和 Exclude 方法和 Dispose 方法。

此示例旨在与 Windows 窗体一起使用。 将代码粘贴到窗体中,并在处理表单的事件时调用FillRegionExcludingPath该方法,并作为传递方式Paint传递ePaintEventArgs

private:
   void FillRegionExcludingPath( PaintEventArgs^ e )
   {
      // Create the region using a rectangle.
      System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( Rectangle(20,20,100,100) );

      // Create the GraphicsPath.
      System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath;

      // Add a circle to the graphics path.
      path->AddEllipse( 50, 50, 25, 25 );

      // Exclude the circle from the region.
      myRegion->Exclude( path );

      // Retrieve a Graphics object from the form.
      Graphics^ formGraphics = e->Graphics;

      // Fill the region in blue.
      formGraphics->FillRegion( Brushes::Blue, myRegion );

      // Dispose of the path and region objects.
      delete path;
      delete myRegion;
   }
private void FillRegionExcludingPath(PaintEventArgs e)
{

    // Create the region using a rectangle.
    Region myRegion = new Region(new Rectangle(20, 20, 100, 100));

    // Create the GraphicsPath.
    System.Drawing.Drawing2D.GraphicsPath path = 
        new System.Drawing.Drawing2D.GraphicsPath();

    // Add a circle to the graphics path.
    path.AddEllipse(50, 50, 25, 25);

    // Exclude the circle from the region.
    myRegion.Exclude(path);

    // Retrieve a Graphics object from the form.
    Graphics formGraphics = e.Graphics;

    // Fill the region in blue.
    formGraphics.FillRegion(Brushes.Blue, myRegion);

    // Dispose of the path and region objects.
    path.Dispose();
    myRegion.Dispose();
}
Private Sub FillRegionExcludingPath(ByVal e As PaintEventArgs)

    ' Create the region using a rectangle.
    Dim myRegion As New Region(New Rectangle(20, 20, 100, 100))

    ' Create the GraphicsPath.
    Dim path As New System.Drawing.Drawing2D.GraphicsPath

    ' Add a circle to the graphics path.
    path.AddEllipse(50, 50, 25, 25)

    ' Exclude the circle from the region.
    myRegion.Exclude(path)

    ' Retrieve a Graphics object from the form.
    Dim formGraphics As Graphics = e.Graphics

    ' Fill the region in blue.
    formGraphics.FillRegion(Brushes.Blue, myRegion)

    ' Dispose of the path and region objects.
    path.Dispose()
    myRegion.Dispose()

End Sub

适用于

Exclude(Rectangle)

更新此项 Region 以仅包含其内部不与指定 Rectangle 结构相交的部分。

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

参数

rect
Rectangle

Rectangle要从中Region排除的结构。

示例

有关代码示例,请参阅该方法 Exclude(RectangleF)

适用于

Exclude(RectangleF)

更新此项 Region 以仅包含其内部不与指定 RectangleF 结构相交的部分。

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

参数

rect
RectangleF

RectangleF要从中Region排除的结构。

示例

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

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

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

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

  • 当与第二个矩形组合时,获取区域的非excluded 区域。

  • 用蓝色填充非封闭区域,并将其绘制到屏幕。

请注意,不与矩形相交的区域的区域的颜色为蓝色。

public:
   void Exclude_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 nonexcluded area of myRegion when combined with
      // complementRect.
      myRegion->Exclude( complementRect );
      
      // Fill the nonexcluded area of myRegion with blue.
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
      e->Graphics->FillRegion( myBrush, myRegion );
   }
public void Exclude_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 nonexcluded area of myRegion when combined with
             
    // complementRect.
    myRegion.Exclude(complementRect);
             
    // Fill the nonexcluded area of myRegion with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Exclude_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 nonexcluded area of myRegion when combined with
    ' complementRect.
    myRegion.Exclude(complementRect)

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

适用于