Region Region Region Region Class

定义

指示由矩形和由路径构成的图形形状的内部。Describes the interior of a graphics shape composed of rectangles and paths. 此类不能被继承。This class cannot be inherited.

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

示例

下面的代码示例旨在与 Windows 窗体一起使用, 并且它需要PaintEventArgs e作为Paint事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码示例Data演示如何使用从一个RegionData对象为另RegionData一个对象设置DataThe code example demonstrates how to use the Data from one RegionData object to set the Data for another RegionData.

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

注解

区域是可伸缩的, 因为它的坐标是在世界坐标中指定的。A region is scalable because its coordinates are specified in world coordinates. 但在绘图图面上, 其内部依赖于表示它的像素的大小和形状。On a drawing surface, however, its interior is dependent on the size and shape of the pixels representing it. 应用程序可以使用区域来剪裁绘图操作的输出。An application can use regions to clip the output of drawing operations. 这些区域称为剪辑区域。These regions are called clipping regions. 有关使用区域进行剪辑的详细信息, 请参阅如何:使用区域的剪辑。For more information on using regions for clipping, see How to: Use Clipping with a Region.

应用程序还可以使用命中测试操作中的区域, 如检查某个点或矩形是否与某个区域相交。An application can also use regions in hit-testing operations, such as checking whether a point or a rectangle intersects a region. 有关使用区域进行命中测试的详细信息, 请参阅如何:对区域使用命中测试。For more information on using regions for hit-testing, see How to: Use Hit Testing with a Region.

应用程序可以使用Graphics.FillRegion方法Brush和对象填充区域。An application can fill a region by using the Graphics.FillRegion method and a Brush object.

构造函数

Region() Region() Region() Region()

初始化新的 RegionInitializes a new Region.

Region(GraphicsPath) Region(GraphicsPath) Region(GraphicsPath) Region(GraphicsPath)

使用指定的 GraphicsPath 初始化新的 RegionInitializes a new Region with the specified GraphicsPath.

Region(Rectangle) Region(Rectangle) Region(Rectangle) Region(Rectangle)

基于指定的 Region 结构初始化一个新的 RectangleInitializes a new Region from the specified Rectangle structure.

Region(RectangleF) Region(RectangleF) Region(RectangleF) Region(RectangleF)

基于指定的 Region 结构初始化一个新的 RectangleFInitializes a new Region from the specified RectangleF structure.

Region(RegionData) Region(RegionData) Region(RegionData) Region(RegionData)

从指定的数据中初始化新的 RegionInitializes a new Region from the specified data.

方法

Clone() Clone() Clone() Clone()

创建此 Region 的一个精确副本。Creates an exact copy of this Region.

Complement(GraphicsPath) Complement(GraphicsPath) Complement(GraphicsPath) Complement(GraphicsPath)

更新此 Region 以包含与此 Region 不相交的指定的 GraphicsPath 的那部分。Updates this Region to contain the portion of the specified GraphicsPath that does not intersect with this Region.

Complement(Rectangle) Complement(Rectangle) Complement(Rectangle) Complement(Rectangle)

更新此 Region,以包含指定的 Rectangle 结构中与此 Region 不相交的部分。Updates this Region to contain the portion of the specified Rectangle structure that does not intersect with this Region.

Complement(RectangleF) Complement(RectangleF) Complement(RectangleF) Complement(RectangleF)

更新此 Region,以包含指定的 RectangleF 结构中与此 Region 不相交的部分。Updates this Region to contain the portion of the specified RectangleF structure that does not intersect with this Region.

Complement(Region) Complement(Region) Complement(Region) Complement(Region)

更新此 Region 以包含与此 Region 不相交的指定的 Region 的那部分。Updates this Region to contain the portion of the specified Region that does not intersect with this Region.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放此 Region 使用的所有资源。Releases all resources used by this Region.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Equals(Region, Graphics) Equals(Region, Graphics) Equals(Region, Graphics) Equals(Region, Graphics)

测试指定的 Region 是否与指定绘图图面上的此 Region 完全相同。Tests whether the specified Region is identical to this Region on the specified drawing surface.

Exclude(GraphicsPath) Exclude(GraphicsPath) Exclude(GraphicsPath) Exclude(GraphicsPath)

更新此 Region,以仅包含其内部与指定的 GraphicsPath 不相交的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified GraphicsPath.

Exclude(Rectangle) Exclude(Rectangle) Exclude(Rectangle) Exclude(Rectangle)

更新此 Region,以仅包含其内部与指定的 Rectangle 结构不相交的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.

Exclude(RectangleF) Exclude(RectangleF) Exclude(RectangleF) Exclude(RectangleF)

更新此 Region,以仅包含其内部与指定的 RectangleF 结构不相交的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified RectangleF structure.

Exclude(Region) Exclude(Region) Exclude(Region) Exclude(Region)

更新此 Region,以仅包含其内部与指定的 Region 不相交的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified Region.

Finalize() Finalize() Finalize() Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromHrgn(IntPtr) FromHrgn(IntPtr) FromHrgn(IntPtr) FromHrgn(IntPtr)

基于指定的现有 GDIGDI 区域的句柄初始化一个新的 RegionInitializes a new Region from a handle to the specified existing GDIGDI region.

GetBounds(Graphics) GetBounds(Graphics) GetBounds(Graphics) GetBounds(Graphics)

获取一个表示矩形的 RectangleF 结构,该矩形在 Region 对象的绘图图面上形成此 Graphics 的边界。Gets a RectangleF structure that represents a rectangle that bounds this Region on the drawing surface of a Graphics object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetHrgn(Graphics) GetHrgn(Graphics) GetHrgn(Graphics) GetHrgn(Graphics)

返回指定图形上下文中此 Region 的 Windows 句柄。Returns a Windows handle to this Region in the specified graphics context.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetRegionData() GetRegionData() GetRegionData() GetRegionData()

返回 RegionData,它表示描述此 Region 的信息。Returns a RegionData that represents the information that describes this Region.

GetRegionScans(Matrix) GetRegionScans(Matrix) GetRegionScans(Matrix) GetRegionScans(Matrix)

返回 RectangleF 结构的数组,这些结构在应用指定的矩阵变换后近似于 RegionReturns an array of RectangleF structures that approximate this Region after the specified matrix transformation is applied.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Intersect(GraphicsPath) Intersect(GraphicsPath) Intersect(GraphicsPath) Intersect(GraphicsPath)

通过指定的 GraphicsPath,将此 Region 更新为其自身的交集。Updates this Region to the intersection of itself with the specified GraphicsPath.

Intersect(Rectangle) Intersect(Rectangle) Intersect(Rectangle) Intersect(Rectangle)

将此 Region 更新为其自身与指定的 Rectangle 结构的交集。Updates this Region to the intersection of itself with the specified Rectangle structure.

Intersect(RectangleF) Intersect(RectangleF) Intersect(RectangleF) Intersect(RectangleF)

将此 Region 更新为其自身与指定的 RectangleF 结构的交集。Updates this Region to the intersection of itself with the specified RectangleF structure.

Intersect(Region) Intersect(Region) Intersect(Region) Intersect(Region)

通过指定的 Region,将此 Region 更新为其自身的交集。Updates this Region to the intersection of itself with the specified Region.

IsEmpty(Graphics) IsEmpty(Graphics) IsEmpty(Graphics) IsEmpty(Graphics)

测试此 Region 在指定绘图图面上是否有空的内部。Tests whether this Region has an empty interior on the specified drawing surface.

IsInfinite(Graphics) IsInfinite(Graphics) IsInfinite(Graphics) IsInfinite(Graphics)

测试此 Region 在指定绘图图面上是否有无限内部。Tests whether this Region has an infinite interior on the specified drawing surface.

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

测试指定的点在用指定的 Region 对象绘制时是否包含在此 Graphics 对象内。Tests whether the specified point is contained within this Region object when drawn using the specified Graphics object.

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

测试指定的矩形是否有任何部分包含在此 Region 中。Tests whether any portion of the specified rectangle is contained within this Region.

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

测试指定的矩形在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。Tests whether any portion of the specified rectangle is contained within this Region when drawn using the specified Graphics.

IsVisible(Point) IsVisible(Point) IsVisible(Point) IsVisible(Point)

测试指定 Point 结构是否包含在此 Region 中。Tests whether the specified Point structure is contained within this Region.

IsVisible(Point, Graphics) IsVisible(Point, Graphics) IsVisible(Point, Graphics) IsVisible(Point, Graphics)

测试指定的 Point 结构在使用指定的 Region 绘制后是否包含在此 Graphics 中。Tests whether the specified Point structure is contained within this Region when drawn using the specified Graphics.

IsVisible(PointF) IsVisible(PointF) IsVisible(PointF) IsVisible(PointF)

测试指定 PointF 结构是否包含在此 Region 中。Tests whether the specified PointF structure is contained within this Region.

IsVisible(PointF, Graphics) IsVisible(PointF, Graphics) IsVisible(PointF, Graphics) IsVisible(PointF, Graphics)

测试指定的 PointF 结构在使用指定的 Region 绘制后是否包含在此 Graphics 中。Tests whether the specified PointF structure is contained within this Region when drawn using the specified Graphics.

IsVisible(Rectangle) IsVisible(Rectangle) IsVisible(Rectangle) IsVisible(Rectangle)

测试指定的 Rectangle 结构是否有任何部分包含在此 Region 中。Tests whether any portion of the specified Rectangle structure is contained within this Region.

IsVisible(Rectangle, Graphics) IsVisible(Rectangle, Graphics) IsVisible(Rectangle, Graphics) IsVisible(Rectangle, Graphics)

测试指定的 Rectangle 结构在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。Tests whether any portion of the specified Rectangle structure is contained within this Region when drawn using the specified Graphics.

IsVisible(RectangleF) IsVisible(RectangleF) IsVisible(RectangleF) IsVisible(RectangleF)

测试指定的 RectangleF 结构是否有任何部分包含在此 Region 中。Tests whether any portion of the specified RectangleF structure is contained within this Region.

IsVisible(RectangleF, Graphics) IsVisible(RectangleF, Graphics) IsVisible(RectangleF, Graphics) IsVisible(RectangleF, Graphics)

测试指定的 RectangleF 结构在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。Tests whether any portion of the specified RectangleF structure is contained within this Region when drawn using the specified Graphics.

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

测试指定点是否包含在此 Region 中。Tests whether the specified point is contained within this Region.

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

测试指定点在使用指定的 Region 绘制后是否包含在此 Graphics 中。Tests whether the specified point is contained within this Region when drawn using the specified Graphics.

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

测试指定的矩形是否有任何部分包含在此 Region 中。Tests whether any portion of the specified rectangle is contained within this Region.

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

测试指定的矩形在使用指定的 Region 绘制后是否有任何部分包含在此 Graphics 中。Tests whether any portion of the specified rectangle is contained within this Region when drawn using the specified Graphics.

MakeEmpty() MakeEmpty() MakeEmpty() MakeEmpty()

将此 Region 初始化为一个空内部。Initializes this Region to an empty interior.

MakeInfinite() MakeInfinite() MakeInfinite() MakeInfinite()

将此 Region 对象初始化为无限内部。Initializes this Region object to an infinite interior.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ReleaseHrgn(IntPtr) ReleaseHrgn(IntPtr) ReleaseHrgn(IntPtr) ReleaseHrgn(IntPtr)

释放 Region 的句柄。Releases the handle of the Region.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
Transform(Matrix) Transform(Matrix) Transform(Matrix) Transform(Matrix)

通过指定的 Region 变换此 MatrixTransforms this Region by the specified Matrix.

Translate(Int32, Int32) Translate(Int32, Int32) Translate(Int32, Int32) Translate(Int32, Int32)

将此 Region 的坐标偏移指定的量。Offsets the coordinates of this Region by the specified amount.

Translate(Single, Single) Translate(Single, Single) Translate(Single, Single) Translate(Single, Single)

将此 Region 的坐标偏移指定的量。Offsets the coordinates of this Region by the specified amount.

Union(GraphicsPath) Union(GraphicsPath) Union(GraphicsPath) Union(GraphicsPath)

将此 Region 更新为其自身与指定 GraphicsPath 的并集。Updates this Region to the union of itself and the specified GraphicsPath.

Union(Rectangle) Union(Rectangle) Union(Rectangle) Union(Rectangle)

将此 Region 更新为其自身与指定 Rectangle 结构的并集。Updates this Region to the union of itself and the specified Rectangle structure.

Union(RectangleF) Union(RectangleF) Union(RectangleF) Union(RectangleF)

将此 Region 更新为其自身与指定 RectangleF 结构的并集。Updates this Region to the union of itself and the specified RectangleF structure.

Union(Region) Union(Region) Union(Region) Union(Region)

将此 Region 更新为其自身与指定 Region 的并集。Updates this Region to the union of itself and the specified Region.

Xor(GraphicsPath) Xor(GraphicsPath) Xor(GraphicsPath) Xor(GraphicsPath)

将此 Region 更新为其自身与指定 GraphicsPath 的并集减去这两者的交集。Updates this Region to the union minus the intersection of itself with the specified GraphicsPath.

Xor(Rectangle) Xor(Rectangle) Xor(Rectangle) Xor(Rectangle)

将此 Region 更新为其自身与指定 Rectangle 结构的并集减去这两者的交集。Updates this Region to the union minus the intersection of itself with the specified Rectangle structure.

Xor(RectangleF) Xor(RectangleF) Xor(RectangleF) Xor(RectangleF)

将此 Region 更新为其自身与指定 RectangleF 结构的并集减去这两者的交集。Updates this Region to the union minus the intersection of itself with the specified RectangleF structure.

Xor(Region) Xor(Region) Xor(Region) Xor(Region)

将此 Region 更新为其自身与指定 Region 的并集减去这两者的交集。Updates this Region to the union minus the intersection of itself with the specified Region.

适用于

另请参阅