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

將此 Region 更新為本身的聯集和指定的 GraphicsPath

C#
public void Union (System.Drawing.Drawing2D.GraphicsPath path);

參數

path
GraphicsPath

要與這個 Region聯合的 GraphicsPath

例外狀況

path null

範例

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

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Union(Rectangle)

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

將此 Region 更新為本身的聯集和指定的 Rectangle 結構。

C#
public void Union (System.Drawing.Rectangle rect);

參數

rect
Rectangle

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

範例

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

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Union(RectangleF)

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

將此 Region 更新為本身的聯集和指定的 RectangleF 結構。

C#
public void Union (System.Drawing.RectangleF rect);

參數

rect
RectangleF

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

範例

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

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

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

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

  • 當與 complementRect結合時,取得 myRegion 的聯集區域。

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

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

C#
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);
}

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Union(Region)

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

將此 Region 更新為本身的聯集和指定的 Region

C#
public void Union (System.Drawing.Region region);

參數

region
Region

要與這個 Region聯合的 Region

例外狀況

region null

範例

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

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9