Share via


Region.Dispose Yöntem

Tanım

Bu Regiontarafından kullanılan tüm kaynakları serbest bırakır.

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

Uygulamalar

Örnekler

Aşağıdaki kod örneği oluşturucuyu Region ve Exclude ve Dispose yöntemlerini gösterir.

Bu örnek, Windows Forms ile kullanılacak şekilde tasarlanmıştır. Kodu bir forma yapıştırın ve formun FillRegionExcludingPathPaint olayını işlerken yöntemini çağırın e ve olarak geçirin 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

Açıklamalar

Çağırma Dispose , bunun Region kullandığı kaynakların başka amaçlarla yeniden ayrılmasını sağlar.

kullanmayı bitirdiğinizde öğesini çağırın DisposeRegion. Dispose yöntemi, Region öğesini kullanılamaz durumda bırakır. çağrısı Disposeyaptıktan sonra, çöp toplayıcının Region , yer kaplayan belleği geri kazanabilmesi için tüm başvurularını Region serbest bırakmanız gerekir. Daha fazla bilgi için bkz. Yönetilmeyen Kaynakları Temizleme ve Atma Yöntemi Uygulama.

Not

son başvurunuzu yayınlamadan önce her zaman çağrısında Dispose bulunur Region. Aksi takdirde, atık toplayıcı nesnenin Finalize yöntemini çağırana Region kadar kullandığı kaynaklar serbest kalır.

Şunlara uygulanır