Region 类

定义

指示由矩形和由路径构成的图形形状的内部。 此类不能被继承。

public ref class Region sealed : MarshalByRefObject, IDisposable
public sealed class Region : MarshalByRefObject, IDisposable
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class Region : MarshalByRefObject, IDisposable
type Region = class
    inherit MarshalByRefObject
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(false)>]
type Region = class
    inherit MarshalByRefObject
    interface IDisposable
Public NotInheritable Class Region
Inherits MarshalByRefObject
Implements IDisposable
继承
属性
实现

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 该代码示例演示如何使用Data一个 对象中的 为另一个 RegionDataRegionData设置 Data

private:
   void DemonstrateRegionData2( PaintEventArgs^ e )
   {
      //Create a simple region.
      System::Drawing::Region^ region1 = gcnew System::Drawing::Region( Rectangle(10,10,100,100) );

      // Extract the region data.
      System::Drawing::Drawing2D::RegionData^ region1Data = region1->GetRegionData();
      array<Byte>^data1;
      data1 = region1Data->Data;

      // Create a second region.
      System::Drawing::Region^ region2 = gcnew System::Drawing::Region;

      // Get the region data for the second region.
      System::Drawing::Drawing2D::RegionData^ region2Data = region2->GetRegionData();

      // Set the Data property for the second region to the Data from the first region.
      region2Data->Data = data1;

      // Construct a third region using the modified RegionData of the second region.
      System::Drawing::Region^ region3 = gcnew System::Drawing::Region( region2Data );

      // Dispose of the first and second regions.
      delete region1;
      delete region2;

      // Call ExcludeClip passing in the third region.
      e->Graphics->ExcludeClip( region3 );

      // Fill in the client rectangle.
      e->Graphics->FillRectangle( Brushes::Red, this->ClientRectangle );
      delete region3;
   }
private void DemonstrateRegionData2(PaintEventArgs e)
{

    //Create a simple region.
    Region region1 = new Region(new Rectangle(10, 10, 100, 100));

    // Extract the region data.
    System.Drawing.Drawing2D.RegionData region1Data = region1.GetRegionData();
    byte[] data1;
    data1 = region1Data.Data;

    // Create a second region.
    Region region2 = new Region();

    // Get the region data for the second region.
    System.Drawing.Drawing2D.RegionData region2Data = region2.GetRegionData();

    // Set the Data property for the second region to the Data from the first region.
    region2Data.Data = data1;

    // Construct a third region using the modified RegionData of the second region.
    Region region3 = new Region(region2Data);

    // Dispose of the first and second regions.
    region1.Dispose();
    region2.Dispose();

    // Call ExcludeClip passing in the third region.
    e.Graphics.ExcludeClip(region3);

    // Fill in the client rectangle.
    e.Graphics.FillRectangle(Brushes.Red, this.ClientRectangle);

    region3.Dispose();
}
Private Sub DemonstrateRegionData2(ByVal e As PaintEventArgs)

    'Create a simple region.
    Dim region1 As New Region(New Rectangle(10, 10, 100, 100))

    ' Extract the region data.
    Dim region1Data As System.Drawing.Drawing2D.RegionData = region1.GetRegionData
    Dim data1() As Byte
    data1 = region1Data.Data

    ' Create a second region.
    Dim region2 As New Region

    ' Get the region data for the second region.
    Dim region2Data As System.Drawing.Drawing2D.RegionData = region2.GetRegionData()

    ' Set the Data property for the second region to the Data from the first region.
    region2Data.Data = data1

    ' Construct a third region using the modified RegionData of the second region.
    Dim region3 As New Region(region2Data)

    ' Dispose of the first and second regions.
    region1.Dispose()
    region2.Dispose()

    ' Call ExcludeClip passing in the third region.
    e.Graphics.ExcludeClip(region3)

    ' Fill in the client rectangle.
    e.Graphics.FillRectangle(Brushes.Red, Me.ClientRectangle)

    region3.Dispose()

End Sub

注解

区域是可缩放的,因为其坐标是在世界坐标中指定的。 但是,在绘图图面上,其内部取决于表示它的像素的大小和形状。 应用程序可以使用区域来剪裁绘图操作的输出。 这些区域称为剪辑区域。 有关使用区域进行剪辑的详细信息,请参阅 如何:对区域使用剪辑

应用程序还可以在命中测试操作中使用区域,例如检查点或矩形是否与区域相交。 有关使用区域进行命中测试的详细信息,请参阅 如何:对区域使用命中测试

应用程序可以使用 方法和 Brush 对象填充区域Graphics.FillRegion

注意

在 .NET 6 及更高版本中, System.Drawing.Common 包(包括此类型)仅在 Windows 操作系统上受支持。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 System.Drawing.Common 仅在 Windows 上受支持

构造函数

Region()

初始化新的 Region

Region(GraphicsPath)

使用指定的 GraphicsPath 初始化新的 Region

Region(Rectangle)

基于指定的 Region 结构初始化一个新的 Rectangle

Region(RectangleF)

基于指定的 Region 结构初始化一个新的 RectangleF

Region(RegionData)

从指定的数据中初始化新的 Region

方法

Clone()

创建此 Region 的一个精确副本。

Complement(GraphicsPath)

更新此 Region 以包含与此 Region 不相交的指定的 GraphicsPath 的那部分。

Complement(Rectangle)

更新此 Region,以包含指定的 Rectangle 结构中与此 Region 不相交的部分。

Complement(RectangleF)

更新此 Region,以包含指定的 RectangleF 结构中与此 Region 不相交的部分。

Complement(Region)

更新此 Region 以包含与此 Region 不相交的指定的 Region 的那部分。

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放此 Region 使用的所有资源。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Equals(Region, Graphics)

测试指定的 Region 是否与指定绘图图面上的此 Region 完全相同。

Exclude(GraphicsPath)

更新此 Region,以仅包含其内部与指定的 GraphicsPath 不相交的部分。

Exclude(Rectangle)

更新此 Region,以仅包含其内部与指定的 Rectangle 结构不相交的部分。

Exclude(RectangleF)

更新此 Region,以仅包含其内部与指定的 RectangleF 结构不相交的部分。

Exclude(Region)

更新此 Region,以仅包含其内部与指定的 Region 不相交的部分。

Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。

FromHrgn(IntPtr)

从指定现有 GDI 区域的句柄初始化新的 Region

GetBounds(Graphics)

获取一个表示矩形的 RectangleF 结构,该矩形在 Region 对象的绘图图面上形成此 Graphics 的边界。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetHrgn(Graphics)

返回指定图形上下文中此 Region 的 Windows 句柄。

GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetRegionData()

返回 RegionData,它表示描述此 Region 的信息。

GetRegionScans(Matrix)

返回 RectangleF 结构的数组,这些结构在应用指定的矩阵变换后近似于 Region

GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
Intersect(GraphicsPath)

通过指定的 GraphicsPath,将此 Region 更新为其自身的交集。

Intersect(Rectangle)

将此 Region 更新为其自身与指定的 Rectangle 结构的交集。

Intersect(RectangleF)

将此 Region 更新为其自身与指定的 RectangleF 结构的交集。

Intersect(Region)

通过指定的 Region,将此 Region 更新为其自身的交集。

IsEmpty(Graphics)

测试此 Region 在指定绘图图面上是否有空的内部。

IsInfinite(Graphics)

测试此 Region 在指定绘图图面上是否有无限内部。

IsVisible(Int32, Int32, Graphics)

测试指定的点在用指定的 Region 对象绘制时是否包含在此 Graphics 对象内。

IsVisible(Int32, Int32, Int32, Int32)

测试指定的矩形是否有任何部分包含在此 Region 中。

IsVisible(Int32, Int32, Int32, Int32, Graphics)

测试指定的矩形在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。

IsVisible(Point)

测试指定 Point 结构是否包含在此 Region 中。

IsVisible(Point, Graphics)

测试指定的 Point 结构在使用指定的 Region 绘制后是否包含在此 Graphics 中。

IsVisible(PointF)

测试指定 PointF 结构是否包含在此 Region 中。

IsVisible(PointF, Graphics)

测试指定的 PointF 结构在使用指定的 Region 绘制后是否包含在此 Graphics 中。

IsVisible(Rectangle)

测试指定的 Rectangle 结构是否有任何部分包含在此 Region 中。

IsVisible(Rectangle, Graphics)

测试指定的 Rectangle 结构在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。

IsVisible(RectangleF)

测试指定的 RectangleF 结构是否有任何部分包含在此 Region 中。

IsVisible(RectangleF, Graphics)

测试指定的 RectangleF 结构在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。

IsVisible(Single, Single)

测试指定点是否包含在此 Region 中。

IsVisible(Single, Single, Graphics)

测试指定点在使用指定的 Region 绘制后是否包含在此 Graphics 中。

IsVisible(Single, Single, Single, Single)

测试指定的矩形是否有任何部分包含在此 Region 中。

IsVisible(Single, Single, Single, Single, Graphics)

测试指定的矩形在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。

MakeEmpty()

将此 Region 初始化为一个空内部。

MakeInfinite()

将此 Region 对象初始化为无限内部。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ReleaseHrgn(IntPtr)

释放该 Region 的句柄。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
Transform(Matrix)

通过指定的 Region 变换此 Matrix

Translate(Int32, Int32)

将此 Region 的坐标偏移指定的量。

Translate(Single, Single)

将此 Region 的坐标偏移指定的量。

Union(GraphicsPath)

将此 Region 更新为其自身与指定 GraphicsPath 的并集。

Union(Rectangle)

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

Union(RectangleF)

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

Union(Region)

将此 Region 更新为其自身与指定 Region 的并集。

Xor(GraphicsPath)

将此 Region 更新为其自身与指定 GraphicsPath 的并集减去这两者的交集。

Xor(Rectangle)

将此 Region 更新为其自身与指定 Rectangle 结构的并集减去这两者的交集。

Xor(RectangleF)

将此 Region 更新为其自身与指定 RectangleF 结构的并集减去这两者的交集。

Xor(Region)

将此 Region 更新为其自身与指定 Region 的并集减去这两者的交集。

适用于

另请参阅