Language

Region.Dispose メソッド

定義

この Regionで使用されているすべてのリソースを解放します。

public:
 virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

実装

例

次のコード例は、 Region コンストラクターと、 Exclude メソッドと Dispose メソッドを示しています。

この例は、Windows フォームで使用するように設計されています。 フォームにコードを貼り付け、フォームのFillRegionExcludingPath イベントを処理するときにPaint メソッドを呼び出し、eとしてPaintEventArgs渡します。

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.Graphics;

    // Fill the region in blue.
    formGraphics.FillRegion(Brushes.Blue, myRegion);

    // Dispose of the path and region objects.
    path.Dispose();
    myRegion.Dispose();
}
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

注釈

Disposeを呼び出すと、このRegionで使用されるリソースを他の目的で再割り当てできます。

Disposeの使用が完了したら、Regionを呼び出します。 Dispose メソッドは、Regionを使用できない状態のままにします。 Disposeを呼び出した後、Regionが占有していたメモリをガベージ コレクターが再利用できるように、Regionへのすべての参照を解放する必要があります。 詳細については、「 アンマネージ リソースのクリーンアップ と Dispose メソッドの実装」を参照してください。

Note

Disposeへの最後の参照を解放する前に、必ずRegionを呼び出してください。 それ以外の場合、ガベージ コレクターが Region オブジェクトの Finalize メソッドを呼び出すまで、使用しているリソースは解放されません。

適用対象