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 Forms 使用,而且需要 PaintEventArgse,這是事件處理程序的參數Paint。 此程式代碼範例示範如何使用Data來自某個 物件的 來設定Data另一RegionDataRegionData的 。

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 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時間警告和運行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

建構函式

Region()

初始化新的 Region

Region(GraphicsPath)

使用指定的 GraphicsPath,將新的 Region 初始化。

Region(Rectangle)

從指定的 Region 結構,初始化新的 Rectangle

Region(RectangleF)

從指定的 Region 結構,初始化新的 RectangleF

Region(RegionData)

從指定的資料將新的 Region 初始化。

方法

Clone()

建立這個 Region 的完全相同複本。

Complement(GraphicsPath)

更新此 Region 以包含指定的 GraphicsPath 部分,其未與此 Region 交集。

Complement(Rectangle)

更新這個 Region,以包含不與這個 Rectangle 交集的指定 Region 結構部分。

Complement(RectangleF)

更新這個 Region,以包含不與這個 RectangleF 交集的指定 Region 結構部分。

Complement(Region)

更新此 Region 以包含指定的 Region 部分,其未與此 Region 交集。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 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()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetRegionData()

傳回 RegionData 物件,表示描述這個 Region 的資訊。

GetRegionScans(Matrix)

傳回 RectangleF 結構的陣列,這些結構會在套用指定的轉換矩陣後近似於這個 Region

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
Intersect(GraphicsPath)

將此 Region 更新到其本身與指定之 GraphicsPath 的交集。

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 的交集。

適用於

另請參閱