語言

Region.Exclude 方法

定義

將此 Region 更新為不與指定 Rectangle 結構相交的內部部分。

多載

名稱 Description
Exclude(Region)

更新此參數 Region ,僅包含與指定 Region區域不相交的內部部分。

Exclude(GraphicsPath)

更新此參數 Region ,僅包含與指定 GraphicsPath區域不相交的內部部分。

Exclude(Rectangle)

更新為 Region 僅包含與指定 Rectangle 結構不相交的內部部分。

Exclude(RectangleF)

更新為 Region 僅包含與指定 RectangleF 結構不相交的內部部分。

Exclude(Region)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此參數 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排除。

例外狀況

region 是 null。

範例

關於程式碼範例,請參見 and Exclude(RectangleF) 方法。Complement(Region)

適用於

Exclude(GraphicsPath)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新此參數 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排除。

例外狀況

path 是 null。

範例

以下程式碼範例展示了 Region 建構子與 Exclude and Dispose 方法。

此範例設計用於 Windows 表單。 將程式碼貼到表單中,處理表單FillRegionExcludingPath事件時呼叫該Paint方法,傳遞e為 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

適用於

Exclude(Rectangle)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新為 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.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

更新為 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 參數。 此程式碼會執行下列動作:

  • 建立一個矩形並以黑色畫到螢幕上

  • 會產生第二個矩形,與第一個相交,並以紅色畫出畫面。

  • 用第一個矩形建立一個區域。

  • 結合第二個矩形時,得到該區域的非排斥面積。

  • 用藍色填滿未被排除的區域,並繪製到螢幕上。

注意該區域中不與矩形相交的區域以藍色標示。

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

適用於