Region.Dispose メソッド
アセンブリ: System.Drawing (system.drawing.dll 内)


Dispose を呼び出すと、Region によって使用されているリソースを他の目的のために再割り当てできます。
Region を使い終わったら、Dispose を呼び出します。Dispose メソッドは、Region を使用できない状態にします。Dispose を呼び出した後で、Region へのすべての参照を解放し、Region によって占有されていたメモリをガベージ コレクタがクリアできるようにする必要があります。詳細については、アンマネージ リソースのクリーンアップ、Dispose メソッドの実装 の各トピックを参照してください。
![]() |
---|
Region への参照をすべて解放してしまう前に、必ず Dispose を呼び出してください。このメソッドを呼び出さないと、カーソルが使用しているリソースは、ガベージ コレクションによって Region オブジェクトの Finalize メソッドが呼び出されるまで解放されません。 |

Region コンストラクタ、Exclude メソッド、および Dispose メソッドを使ったコード例を次に示します。
この例は、Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、フォームの Paint イベントを処理するときに PaintEventArgs の e を渡して FillRegionExcludingPath メソッドを呼び出します。
Private Sub FillRegionExcludingPath(ByVal e As PaintEventArgs) ' Create the region using a rectangle. Dim myRegion As New Region(New Rectangle(20, 20, 100, 100)) ' Create the GraphicsPath. Dim path As New System.Drawing.Drawing2D.GraphicsPath ' Add a circle to the graphics path. path.AddEllipse(50, 50, 25, 25) ' Exclude the circle from the region. myRegion.Exclude(path) ' Retrieve a Graphics object from the form. Dim formGraphics As Graphics = e.Graphics ' Fill the region in blue. formGraphics.FillRegion(Brushes.Blue, myRegion) ' Dispose of the path and region objects. path.Dispose() myRegion.Dispose() End Sub
private void FillRegionExcludingPath(PaintEventArgs e) { // Create the region using a rectangle. Region myRegion = new Region(new Rectangle(20, 20, 100, 100)); // Create the GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // Add a circle to the graphics path. path.AddEllipse(50, 50, 25, 25); // Exclude the circle from the region. myRegion.Exclude(path); // Retrieve a Graphics object from the form. Graphics formGraphics = e.Graphics; // Fill the region in blue. formGraphics.FillRegion(Brushes.Blue, myRegion); // Dispose of the path and region objects. path.Dispose(); myRegion.Dispose(); }
private: void FillRegionExcludingPath( PaintEventArgs^ e ) { // Create the region using a rectangle. System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( Rectangle(20,20,100,100) ); // Create the GraphicsPath. System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath; // Add a circle to the graphics path. path->AddEllipse( 50, 50, 25, 25 ); // Exclude the circle from the region. myRegion->Exclude( path ); // Retrieve a Graphics object from the form. Graphics^ formGraphics = e->Graphics; // Fill the region in blue. formGraphics->FillRegion( Brushes::Blue, myRegion ); // Dispose of the path and region objects. delete path; delete myRegion; }
private void FillRegionExcludingPath(PaintEventArgs e) { // Create the region using a rectangle. Region myRegion = new Region(new Rectangle(20, 20, 100, 100)); // Create the GraphicsPath. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // Add a circle to the graphics path. path.AddEllipse(50, 50, 25, 25); // Exclude the circle from the region. myRegion.Exclude(path); // Retrieve a Graphics object from the form. Graphics formGraphics = e.get_Graphics(); // Fill the region in blue. formGraphics.FillRegion(Brushes.get_Blue(), myRegion); // Dispose of the path and region objects. path.Dispose(); myRegion.Dispose(); } //FillRegionExcludingPath

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Region.Dispose メソッドのページへのリンク