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 Form 使用,而且需要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物件來設定DataRegionDataThe 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. 如需有關如何使用裁剪區域的詳細資訊,請參閱How to:使用區域的裁剪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. 如需有關如何使用區域的點擊測試的詳細資訊,請參閱How to:使用點擊測試的區域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,將新的 Region 初始化。Initializes 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)

從指定的資料將新的 Region 初始化。Initializes 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 以包含指定的 GraphicsPath 部分,其未與此 Region 交集。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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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)

將此 Region 更新到其本身與指定之 GraphicsPath 的交集。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 的淺層複本 (Shallow Copy)。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.

適用於

另請參閱