Region.Dispose 메서드

정의

Region에서 사용하는 리소스를 모두 해제합니다.

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

구현

예제

다음 코드 예제에서는 Region 생성자 및 ExcludeDispose 메서드입니다.

이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 Paint 이벤트를 처리할 때 메서드를 호출 FillRegionExcludingPath 하여 으로 PaintEventArgs전달합니다e.

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 메서드 구현합니다.

참고

Dispose에 대한 마지막 참조를 해제하기 전에 반드시 Region를 호출하십시오. 이렇게 하지 않으면 가비지 수집기가 Region 개체의 Finalize 메서드를 호출할 때까지 사용 중인 리소스가 해제되지 않습니다.

적용 대상