Share via


Region.Union 方法

定義

將這個 Region 更新為其本身與指定 GraphicsPath 的聯集。

多載

Union(GraphicsPath)

將這個 Region 更新為其本身與指定 GraphicsPath 的聯集。

Union(Rectangle)

將這個 Region 更新為其本身與指定 Rectangle 結構的聯集。

Union(RectangleF)

將這個 Region 更新為其本身與指定 RectangleF 結構的聯集。

Union(Region)

將這個 Region 更新為其本身與指定 Region 的聯集。

Union(GraphicsPath)

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

將這個 Region 更新為其本身與指定 GraphicsPath 的聯集。

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

參數

path
GraphicsPath

要與這個 GraphicsPath 聯集的 Region

例外狀況

pathnull

範例

如需程式代碼範例,請參閱 Union(RectangleF)Complement(GraphicsPath) 方法。

適用於

Union(Rectangle)

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

將這個 Region 更新為其本身與指定 Rectangle 結構的聯集。

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

參數

rect
Rectangle

要與這個 Rectangle 聯集的 Region 結構。

範例

如需程式代碼範例,請參閱 Union(RectangleF) 方法。

適用於

Union(RectangleF)

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

將這個 Region 更新為其本身與指定 RectangleF 結構的聯集。

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

參數

rect
RectangleF

要與這個 RectangleF 聯集的 Region 結構。

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse。 此程式碼會執行下列動作:

  • 建立第一個矩形,並將其繪製到黑色的畫面。

  • 建立第二個矩形,並以紅色繪製到畫面。

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

  • 當與 complementRect結合時,取得的myRegion等位區域。

  • 以藍色填滿等位的區域,並將它繪製到螢幕。

請注意,這兩個矩形會填滿藍色,包括重疊的區域。

void Union_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 unionRect = RectangleF(90,30,100,100);
   e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( unionRect ) );

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

   // Get the area of union for myRegion when combined with
   // complementRect.
   myRegion->Union( unionRect );

   // Fill the union area of myRegion with blue.
   SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
   e->Graphics->FillRegion( myBrush, myRegion );
}
public void Union_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 unionRect = new RectangleF(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red,
        Rectangle.Round(unionRect));
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Get the area of union for myRegion when combined with
             
    // complementRect.
    myRegion.Union(unionRect);
             
    // Fill the union area of myRegion with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub Union_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 unionRect As New RectangleF(90, 30, 100, 100)
    e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(unionRect))

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

    ' Get the area of union for myRegion when combined with
    ' complementRect.
    myRegion.Union(unionRect)

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

適用於

Union(Region)

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

將這個 Region 更新為其本身與指定 Region 的聯集。

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

參數

region
Region

要與這個 Region 聯集的 Region

例外狀況

regionnull

範例

如需程式代碼範例,請參閱 Union(RectangleF)Complement(GraphicsPath) 方法。

適用於