Region 類別

定義

描述由矩形和路徑構成的圖形形狀內部。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 Forms 搭配使用所設計, 而且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一個Data物件的。The 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()

初始化新的 RegionInitializes a new Region.

Region(GraphicsPath)

使用指定的 GraphicsPath,將新的 Region 初始化。Initializes a new Region with the specified GraphicsPath.

Region(Rectangle)

從指定的 Region 結構,初始化新的 RectangleInitializes a new Region from the specified Rectangle structure.

Region(RectangleF)

從指定的 Region 結構,初始化新的 RectangleFInitializes a new Region from the specified RectangleF structure.

Region(RegionData)

從指定的資料將新的 Region 初始化。Initializes a new Region from the specified data.

方法

Clone()

建立這個 Region 的完全相同複本。Creates an exact copy of this Region.

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)

更新這個 Region,以包含不與這個 Rectangle 交集的指定 Region 結構部分。Updates this Region to contain the portion of the specified Rectangle structure that does not intersect with this Region.

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)

更新此 Region 以包含指定的 Region 部分,其未與此 Region 交集。Updates this Region to contain the portion of the specified Region that does not intersect with this Region.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放這個 Region 所使用的所有資源。Releases all resources used by this Region.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Equals(Region, Graphics)

測試指定的 Region 是否在指定的繪圖介面上與這個 Region 相同。Tests whether the specified Region is identical to this Region on the specified drawing surface.

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)

更新這個 Region 物件,以便只包含其內部中不與指定之 Rectangle 結構交集的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.

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)

更新這個 Region,以便只包含其內部中不與指定之 Region 交集的部分。Updates this Region to contain only the portion of its interior that does not intersect with the specified Region.

Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromHrgn(IntPtr)

從指定之現有 GDIGDI 區域的控制代碼,初始化新的 RegionInitializes a new Region from a handle to the specified existing GDIGDI region.

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()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetHrgn(Graphics)

傳回這個 Region 在指定之圖形內容中的 Windows 控制代碼。Returns a Windows handle to this Region in the specified graphics context.

GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetRegionData()

傳回 RegionData 物件,表示描述這個 Region 的資訊。Returns a RegionData that represents the information that describes this Region.

GetRegionScans(Matrix)

傳回 RectangleF 結構的陣列,這些結構會在套用指定的轉換矩陣後近似於這個 RegionReturns an array of RectangleF structures that approximate this Region after the specified matrix transformation is applied.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
Intersect(GraphicsPath)

將此 Region 更新到其本身與指定之 GraphicsPath 的交集。Updates this Region to the intersection of itself with the specified GraphicsPath.

Intersect(Rectangle)

將此 Region 更新到其本身與指定之 Rectangle 結構的交集。Updates this Region to the intersection of itself with the specified Rectangle structure.

Intersect(RectangleF)

將此 Region 更新到其本身與指定之 RectangleF 結構的交集。Updates this Region to the intersection of itself with the specified RectangleF structure.

Intersect(Region)

將此 Region 更新到其本身與指定之 Region 的交集。Updates this Region to the intersection of itself with the specified Region.

IsEmpty(Graphics)

測試這個 Region 在指定的繪圖介面上是否有空的內部。Tests whether this Region has an empty interior on the specified drawing surface.

IsInfinite(Graphics)

測試這個 Region 在指定的繪圖介面上是否有無限內部。Tests whether this Region has an infinite interior on the specified drawing surface.

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)

測試是否有任何指定之矩形的部分包含在這個 Region 中。Tests whether any portion of the specified rectangle is contained within this Region.

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)

測試指定的 Point 結構是否包含在這個 Region 中。Tests whether the specified Point structure is contained within this Region.

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)

測試指定的 PointF 結構是否包含在這個 Region 中。Tests whether the specified PointF structure is contained within this Region.

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)

測試是否有任何指定之 Rectangle 結構的部分包含在這個 Region 中。Tests whether any portion of the specified Rectangle structure is contained within this Region.

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)

測試是否有任何指定之 RectangleF 結構的部分包含在這個 Region 中。Tests whether any portion of the specified RectangleF structure is contained within this Region.

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)

測試指定的點是否包含在這個 Region 中。Tests whether the specified point is contained within this Region.

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)

測試是否有任何指定之矩形的部分包含在這個 Region 中。Tests whether any portion of the specified rectangle is contained within this Region.

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()

將這個 Region 初始化為空的內部。Initializes this Region to an empty interior.

MakeInfinite()

將這個 Region 物件初始化為無限內部。Initializes this Region object to an infinite interior.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ReleaseHrgn(IntPtr)

釋放 Region 的控制代碼。Releases the handle of the Region.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
Transform(Matrix)

藉由指定的 Region 轉換這個 MatrixTransforms this Region by the specified Matrix.

Translate(Int32, Int32)

以指定的數量來位移這個 Region 的座標。Offsets the coordinates of this Region by the specified amount.

Translate(Single, Single)

以指定的數量來位移這個 Region 的座標。Offsets the coordinates of this Region by the specified amount.

Union(GraphicsPath)

將這個 Region 更新為其本身與指定 GraphicsPath 的聯集。Updates this Region to the union of itself and the specified GraphicsPath.

Union(Rectangle)

將這個 Region 更新為其本身與指定 Rectangle 結構的聯集。Updates this Region to the union of itself and the specified Rectangle structure.

Union(RectangleF)

將這個 Region 更新為其本身與指定 RectangleF 結構的聯集。Updates this Region to the union of itself and the specified RectangleF structure.

Union(Region)

將這個 Region 更新為其本身與指定 Region 的聯集。Updates this Region to the union of itself and the specified Region.

Xor(GraphicsPath)

將這個 Region 更新為聯集減去其本身與指定 GraphicsPath 的交集。Updates this Region to the union minus the intersection of itself with the specified GraphicsPath.

Xor(Rectangle)

將這個 Region 更新為聯集減去其本身與指定 Rectangle 結構的交集。Updates this Region to the union minus the intersection of itself with the specified Rectangle structure.

Xor(RectangleF)

將這個 Region 更新為聯集減去其本身與指定 RectangleF 結構的交集。Updates this Region to the union minus the intersection of itself with the specified RectangleF structure.

Xor(Region)

將這個 Region 更新為聯集減去其本身與指定 Region 的交集。Updates this Region to the union minus the intersection of itself with the specified Region.

適用於

另請參閱