Share via


Region.Dispose Metodo

Definizione

Rilascia tutte le risorse usate da questa classe Region.

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

Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato il Region costruttore e i Exclude metodi e Dispose .

Questo esempio è progettato per essere usato con Windows Forms. Incollare il codice in una maschera e chiamare il metodo quando si gestisce l'evento FillRegionExcludingPath del Paint modulo, passando e come 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

Commenti

La chiamata Dispose consente di riallocare le risorse usate da questo Region oggetto per altri scopi.

Chiamare il metodo Dispose dopo aver terminato di utilizzare l'oggetto Region. Il metodo Dispose lascia l'oggetto Region in una condizione di inutilizzabilità. Dopo aver chiamato Dispose, è necessario rilasciare tutti i riferimenti a Region in modo che Region il Garbage Collector possa recuperare la memoria occupata da . Per altre informazioni, vedere Pulizia delle risorse non gestite e Implementazione di un metodo Dispose.

Nota

Chiamare sempre il metodo Dispose prima di rilasciare l'ultimo riferimento a Region. In caso contrario, le risorse utilizzate non verranno liberate finché il metodo Region dell'oggetto Finalize non viene richiamato dal Garbage Collector.

Si applica a