편집

다음을 통해 공유


Region.Exclude Method

Definition

Updates this Region to the portion of its interior that does not intersect with the specified Rectangle structure.

Overloads

Exclude(Region)

Updates this Region to contain only the portion of its interior that does not intersect with the specified Region.

Exclude(GraphicsPath)

Updates this Region to contain only the portion of its interior that does not intersect with the specified GraphicsPath.

Exclude(Rectangle)

Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.

Exclude(RectangleF)

Updates this Region to contain only the portion of its interior that does not intersect with the specified RectangleF structure.

Exclude(Region)

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

Updates this Region to contain only the portion of its interior that does not intersect with the specified 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)

Parameters

region
Region

The Region to exclude from this Region.

Exceptions

region is null.

Examples

For code examples, see the Exclude(RectangleF) and Complement(Region) methods.

Applies to

Exclude(GraphicsPath)

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

Updates this Region to contain only the portion of its interior that does not intersect with the specified 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)

Parameters

path
GraphicsPath

The GraphicsPath to exclude from this Region.

Exceptions

path is null.

Examples

The following code example demonstrates the Region constructor and the Exclude and Dispose methods.

This example is designed to be used with Windows Forms. Paste the code into a form and call the FillRegionExcludingPath method when handling the form's Paint event, passing e as PaintEventArgs.

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

Applies to

Exclude(Rectangle)

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

Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.

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)

Parameters

rect
Rectangle

The Rectangle structure to exclude from this Region.

Examples

For a code example, see the Exclude(RectangleF) method.

Applies to

Exclude(RectangleF)

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

Updates this Region to contain only the portion of its interior that does not intersect with the specified RectangleF structure.

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)

Parameters

rect
RectangleF

The RectangleF structure to exclude from this Region.

Examples

The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a rectangle and draws it to the screen in black

  • Creates a second rectangle that intersects with the first and draws it to the screen in red.

  • Creates a region using the first rectangle.

  • Gets the nonexcluded area of the region when combined with the second rectangle.

  • Fills the nonexcluded area with blue and draws it to the screen.

Notice that the area of the area of the region that does not intersect with the rectangle is colored blue.

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

Applies to