Region 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
描述由矩形和路徑組成的圖形圖形內部。 無法繼承這個類別。
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 事件處理程式的參數。 程式代碼範例示範如何使用某個 RegionData 物件的 Data,為另一個 RegionData設定 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
備註
區域可調整,因為其座標是在世界座標中指定。 不過,在繪圖介面上,其內部取決於代表它的圖元大小和形狀。 應用程式可以使用區域來裁剪繪圖作業的輸出。 這些區域稱為裁剪區域。 如需使用區域進行裁剪的詳細資訊,請參閱 如何:搭配區域使用裁剪。
應用程式也可以在點擊測試作業中使用區域,例如檢查某個點或矩形是否與區域交集。 如需使用區域進行點擊測試的詳細資訊,請參閱 如何:搭配區域使用點擊測試。
應用程式可以使用 Graphics.FillRegion 方法和 Brush 物件來填滿區域。
注意
在 .NET 6 和更新版本中,System.Drawing.Common 套件,僅支援 Windows 操作系統。 在跨平臺應用程式中使用此類型會導致編譯時期警告和運行時間例外狀況。 如需詳細資訊,請參閱僅支援 Windows
建構函式
Region() |
初始化新的 Region。 |
Region(GraphicsPath) |
使用指定的 GraphicsPath,初始化新的 Region。 |
Region(Rectangle) | |
Region(RectangleF) |
從指定的 RectangleF 結構初始化新的 Region。 |
Region(RegionData) |
從指定的數據初始化新的 Region。 |
方法
適用於
另請參閱
- Rectangle
- GraphicsPath
- 使用區域