Region.Union 方法

定义

将此 Region 更新为自身和指定的 GraphicsPath联合。

重载

名称 说明
Union(GraphicsPath)

将此 Region 更新为自身和指定的 GraphicsPath联合。

Union(Rectangle)

将此 Region 更新为自身和指定 Rectangle 结构的并集。

Union(RectangleF)

将此 Region 更新为自身和指定 RectangleF 结构的并集。

Union(Region)

将此 Region 更新为自身和指定的 Region联合。

Union(GraphicsPath)

将此 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 更新为自身和指定 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 更新为自身和指定 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 窗体,并且需要 PaintEventArgse。 该示例执行以下操作:

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

  • 创建第二个矩形并将其绘制到红色屏幕。

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

  • 获取 myRegioncomplementRect..

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

请注意,这两个矩形都填充有蓝色,包括重叠区域。

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 更新为自身和指定的 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)方法。

适用于